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

歡迎訪問 生活随笔!

生活随笔

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

asp.net

XML 读写(命名空间)

發布時間:2023/12/19 asp.net 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 XML 读写(命名空间) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

http://www.w3school.com.cn/xml/xml_namespaces.asp (XML命名空間和xml詳細內容)

?

http://www.w3.org/TR/REC-xml-names/

?

處理含有xml命名空間的讀取

http://www.cnblogs.com/martin-chen/archive/2011/02/24/xml-studynote-namespace.html

?

http://msdn.microsoft.com/zh-cn/library/system.xml.xmlwriter.aspx (.net實現xml讀寫)

?

UTF8:

Many Windows programs (including Windows Notepad) add the bytes 0xEF, 0xBB, 0xBF at the start of any document saved as UTF-8. This is the UTF-8 encoding of the Unicode byte order mark (BOM), and is commonly referred to as a UTF-8 BOM, even though it is not relevant to byte order. The BOM can also appear if another encoding with a BOM is translated to UTF-8 without stripping it. Older text editors may display the BOM as "???" at the start of the document.

?

static?void?Main(string[]?args)
????????{

????????????using?(MemoryStream?ms?=?new?MemoryStream())
????????????{

????????????????XmlWriterSettings?settings?=?new?XmlWriterSettings();

????????????????//要求縮進?

????????????????settings.Indent?=?true;

????????????????//注意如果不設置encoding默認將輸出utf-16?
????????????????
//注意這兒不能直接用Encoding.UTF8如果用Encoding.UTF8將在輸出文本的最前面添加3個字節的非xml內容?
????????????????settings.Encoding?=?Encoding.UTF8;
????????????????//settings.Encoding?=?new?UTF8Encoding(false);

????????????????
//設置換行符?
????????????????settings.NewLineChars?=?Environment.NewLine;

????????????????using?(XmlWriter?xmlWriter?=?XmlWriter.Create(ms,?settings))
????????????????{
????????????????????//寫xml文件開始<?xml?version="1.0"?encoding="utf-8"??>?
?????????????????????xmlWriter.WriteStartDocument(false);

????????????????????//寫根節點?
????????????????????xmlWriter.WriteStartElement("root");

????????????????????//寫字節點?
????????????????????xmlWriter.WriteStartElement("cat");

????????????????????//給節點添加屬性?
????????????????????xmlWriter.WriteAttributeString("color",?"white");

????????????????????//給節點內部添加文本?
????????????????????xmlWriter.WriteString("I'm?a?cat");

????????????????????xmlWriter.WriteEndElement();


????????????????????//通過WriteElementString可以添加一個節點同時添加節點內容?
????????????????????xmlWriter.WriteElementString("pig",?"pig?is?great");

????????????????????xmlWriter.WriteStartElement("dog");

????????????????????//寫CData?
????????????????????xmlWriter.WriteCData("<strong>dog?is?dog</strong>");
????????????????????xmlWriter.WriteEndElement();

????????????????????xmlWriter.WriteComment("this?is?an?example?writed?by?bob");

????????????????????xmlWriter.WriteEndElement();
????????????????????xmlWriter.WriteEndDocument();
????????????????}

????????????????//將xml內容輸出到控制臺中?
????????????????string?xml?=?Encoding.UTF8.GetString(ms.ToArray());
????????????????Console.WriteLine(xml);

????????????}

????????????Console.Read();?



????????}

?結果 1. 使用UTF8:

?

轉載于:https://www.cnblogs.com/Jessy/archive/2012/07/04/2575928.html

總結

以上是生活随笔為你收集整理的XML 读写(命名空间)的全部內容,希望文章能夠幫你解決所遇到的問題。

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