日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

使用XMLSerializerNamespace类生成受限的名称

發布時間:2025/3/13 asp.net 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用XMLSerializerNamespace类生成受限的名称 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Category類的代碼 ?1using?System;
?2using?System.Collections.Generic;
?3using?System.Linq;
?4using?System.Web;
?5using?System.Xml;
?6using?System.Xml.Serialization;
?7
?8/**////?<summary>
?9///?Summary?description?for?Category
10///?</summary>
11///?

12
13[XmlRoot(Namespace="http://northwind.com/category")]
14public?class?Category
15{
16????public?long?CategoryID;
17????public?string?CategoryName;
18????public?string?Description;
19
20????public?Category()
21????{
22????????//
23????????//?TODO:?Add?constructor?logic?here
24????????//
25????}

26}

27

執行代碼:

?

?1using?System;
?2using?System.Collections.Generic;
?3using?System.Linq;
?4using?System.Web;
?5using?System.Web.UI;
?6using?System.Web.UI.WebControls;
?7using?System.IO;
?8using?System.Xml;
?9using?System.Xml.Serialization;
10
11public?partial?class?_Default?:?System.Web.UI.Page?
12{
13????protected?void?Page_Load(object?sender,?EventArgs?e)
14????{
15????????string?xmlFilePath?=?@"c:\Data\Category.xml";
16????????Category?categoryObj?=?new?Category();
17????????categoryObj.CategoryID?=?1;
18????????categoryObj.CategoryName?=?"啤酒";
19????????categoryObj.Description?=?"軟飲料,茶,可口可樂,白酒和紅酒";
20
21????????XmlSerializerNamespaces?namespaces?=?new?XmlSerializerNamespaces();
22????????namespaces.Add("cate",?"http://northwind.com/category");
23????????XmlSerializer?serializer?=?new?XmlSerializer(typeof?(Category));
24????????TextWriter?writer?=?new?StreamWriter(xmlFilePath);
25????????serializer.Serialize(writer,?categoryObj,?namespaces);
26????????writer.Close();
27????????Response.Write("文件寫入成功!");
28
29????}

30}

31

輸出XML結果:

?

1<?xml?version="1.0"?encoding="utf-8"?>
2<cate:Category?xmlns:cate="http://northwind.com/category">
3????<cate:CategoryID>1</cate:CategoryID>
4????<cate:CategoryName>啤酒</cate:CategoryName>
5????<cate:Description>軟飲料,茶,可口可樂,白酒和紅酒</cate:Description>
6</cate:Category>
7

?

轉載于:https://www.cnblogs.com/apiaceae/archive/2009/04/17/1437856.html

總結

以上是生活随笔為你收集整理的使用XMLSerializerNamespace类生成受限的名称的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。