asp.net下創(chuàng)建、查詢、修改帶名稱空間的 XML 文件的例子
更新時(shí)間:2007年04月13日 00:00:00 作者:
C#:
string w3NameSpace = "http://www.w3.org/2000/xmlns/";
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
//創(chuàng)建根節(jié)點(diǎn)
System.Xml.XmlNode root = doc.CreateNode(System.Xml.XmlNodeType.Element, "w", "wordDocument", "http://schemas.microsoft.com/office/word/2003/2/wordml");
System.Xml.XmlAttribute xa;
xa = doc.CreateAttribute("xmlns", "v", w3NameSpace);
xa.Value = "urn:schemas-microsoft-com:vml";
root.Attributes.Append(xa);
//為節(jié)點(diǎn)添加屬性
xa = doc.CreateAttribute("xmlns", "w10", w3NameSpace);
xa.Value = "urn:schemas-microsoft-com:office:word";
root.Attributes.Append(xa);
xa = doc.CreateAttribute("xmlns", "SL", w3NameSpace);
xa.Value = "http://schemas.microsoft.com/schemaLibrary/2003/2/core";
root.Attributes.Append(xa);
xa = doc.CreateAttribute("xmlns", "aml", w3NameSpace);
xa.Value = "http://schemas.microsoft.com/aml/2001/core";
root.Attributes.Append(xa);
xa = doc.CreateAttribute("xmlns", "wx", w3NameSpace);
xa.Value = "http://schemas.microsoft.com/office/word/2003/2/auxHint";
root.Attributes.Append(xa);
xa = doc.CreateAttribute("xmlns", "o", w3NameSpace);
xa.Value = "urn:schemas-microsoft-com:office:office";
root.Attributes.Append(xa);
xa = doc.CreateAttribute("xmlns", "dt", w3NameSpace);
xa.Value = "uuid:C2F41010-65B3-11d1-A29F-00AA00C14882";
root.Attributes.Append(xa);
xa = doc.CreateAttribute("xmlns", "space", w3NameSpace);
xa.Value = "preserve";
root.Attributes.Append(xa);
//為節(jié)點(diǎn)增加值
System.Xml.XmlNode body = doc.CreateNode(System.Xml.XmlNodeType.Element, "v", "body", "urn:schemas-microsoft-com:vml");
System.Xml.XmlNode childNode = doc.CreateNode(System.Xml.XmlNodeType.Element, "o", "t", "urn:schemas-microsoft-com:office:office");
childNode.InnerText = "歡迎光臨【孟憲會(huì)之精彩世界】";
//添加到內(nèi)存樹(shù)中
body.AppendChild(childNode);
root.AppendChild(body);
doc.AppendChild(root);
//添加節(jié)點(diǎn)聲明
System.Xml.XmlDeclaration xd = doc.CreateXmlDeclaration("1.0", "UTF-8", "yes");
doc.InsertBefore(xd, doc.DocumentElement);
//添加處理指令
System.Xml.XmlProcessingInstruction spi = doc.CreateProcessingInstruction("mso-application", "progid=\"Word.Document\"");
doc.InsertBefore(spi, doc.DocumentElement);
//查詢節(jié)點(diǎn)
System.Xml.XmlNamespaceManager nsmanager = new System.Xml.XmlNamespaceManager(doc.NameTable);
nsmanager.AddNamespace("w", "http://schemas.microsoft.com/office/word/2003/2/wordml");
nsmanager.AddNamespace("v", "urn:schemas-microsoft-com:vml");
nsmanager.AddNamespace("o", "urn:schemas-microsoft-com:office:office");
System.Xml.XmlNode node = doc.SelectSingleNode("w:wordDocument/v:body/o:t", nsmanager);
Response.Write(node.InnerText);
node.InnerText = "歡迎光臨【孟憲會(huì)之精彩世界】:http://dotnet.aspx.cc/";
//創(chuàng)建CDATA節(jié)點(diǎn)
System.Xml.XmlCDataSection xcds = doc.CreateCDataSection("<a );
node.ParentNode.InsertAfter(xcds, node);
Response.Write(xcds.InnerText);
doc.Save(Server.MapPath("test.xml"));
VB.net
Dim w3NameSpace As String = "http://www.w3.org/2000/xmlns/"
Dim doc As New System.Xml.XmlDocument
'創(chuàng)建根節(jié)點(diǎn)
Dim root As System.Xml.XmlNode = doc.CreateNode(System.Xml.XmlNodeType.Element, "w", "wordDocument", "http://schemas.microsoft.com/office/word/2003/2/wordml")
Dim xa As System.Xml.XmlAttribute
xa = doc.CreateAttribute("xmlns", "v", w3NameSpace)
xa.Value = "urn:schemas-microsoft-com:vml"
root.Attributes.Append(xa)
'為節(jié)點(diǎn)添加屬性
xa = doc.CreateAttribute("xmlns", "w10", w3NameSpace)
xa.Value = "urn:schemas-microsoft-com:office:word"
root.Attributes.Append(xa)
xa = doc.CreateAttribute("xmlns", "SL", w3NameSpace)
xa.Value = "http://schemas.microsoft.com/schemaLibrary/2003/2/core"
root.Attributes.Append(xa)
xa = doc.CreateAttribute("xmlns", "aml", w3NameSpace)
xa.Value = "http://schemas.microsoft.com/aml/2001/core"
root.Attributes.Append(xa)
xa = doc.CreateAttribute("xmlns", "wx", w3NameSpace)
xa.Value = "http://schemas.microsoft.com/office/word/2003/2/auxHint"
root.Attributes.Append(xa)
xa = doc.CreateAttribute("xmlns", "o", w3NameSpace)
xa.Value = "urn:schemas-microsoft-com:office:office"
root.Attributes.Append(xa)
xa = doc.CreateAttribute("xmlns", "dt", w3NameSpace)
xa.Value = "uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
root.Attributes.Append(xa)
xa = doc.CreateAttribute("xmlns", "space", w3NameSpace)
xa.Value = "preserve"
root.Attributes.Append(xa)
'為節(jié)點(diǎn)增加值
Dim body As System.Xml.XmlNode = doc.CreateNode(System.Xml.XmlNodeType.Element, "v", "body", "urn:schemas-microsoft-com:vml")
Dim childNode As System.Xml.XmlNode = doc.CreateNode(System.Xml.XmlNodeType.Element, "o", "t", "urn:schemas-microsoft-com:office:office")
childNode.InnerText = "歡迎光臨【孟憲會(huì)之精彩世界】"
'添加到內(nèi)存樹(shù)中
body.AppendChild(childNode)
root.AppendChild(body)
doc.AppendChild(root)
'添加節(jié)點(diǎn)聲明
Dim xd As System.Xml.XmlDeclaration = doc.CreateXmlDeclaration("1.0", "UTF-8", "yes")
doc.InsertBefore(xd, doc.DocumentElement)
'添加處理指令
Dim spi As System.Xml.XmlProcessingInstruction = doc.CreateProcessingInstruction("mso-application", "progid=""Word.Document""")
doc.InsertBefore(spi, doc.DocumentElement)
'查詢節(jié)點(diǎn)
Dim nsmanager As New System.Xml.XmlNamespaceManager(doc.NameTable)
nsmanager.AddNamespace("w", "http://schemas.microsoft.com/office/word/2003/2/wordml")
nsmanager.AddNamespace("v", "urn:schemas-microsoft-com:vml")
nsmanager.AddNamespace("o", "urn:schemas-microsoft-com:office:office")
Dim node As System.Xml.XmlNode = doc.SelectSingleNode("w:wordDocument/v:body/o:t", nsmanager)
Response.Write(node.InnerText)
node.InnerText = "歡迎光臨【孟憲會(huì)之精彩世界】:http://dotnet.aspx.cc/"
'創(chuàng)建CDATA節(jié)點(diǎn)
Dim xcds As System.Xml.XmlCDataSection = doc.CreateCDataSection("<a )
node.ParentNode.InsertAfter(xcds, node)
Response.Write(xcds.InnerText)
doc.Save(Server.MapPath("test.xml"))
string w3NameSpace = "http://www.w3.org/2000/xmlns/";
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
//創(chuàng)建根節(jié)點(diǎn)
System.Xml.XmlNode root = doc.CreateNode(System.Xml.XmlNodeType.Element, "w", "wordDocument", "http://schemas.microsoft.com/office/word/2003/2/wordml");
System.Xml.XmlAttribute xa;
xa = doc.CreateAttribute("xmlns", "v", w3NameSpace);
xa.Value = "urn:schemas-microsoft-com:vml";
root.Attributes.Append(xa);
//為節(jié)點(diǎn)添加屬性
xa = doc.CreateAttribute("xmlns", "w10", w3NameSpace);
xa.Value = "urn:schemas-microsoft-com:office:word";
root.Attributes.Append(xa);
xa = doc.CreateAttribute("xmlns", "SL", w3NameSpace);
xa.Value = "http://schemas.microsoft.com/schemaLibrary/2003/2/core";
root.Attributes.Append(xa);
xa = doc.CreateAttribute("xmlns", "aml", w3NameSpace);
xa.Value = "http://schemas.microsoft.com/aml/2001/core";
root.Attributes.Append(xa);
xa = doc.CreateAttribute("xmlns", "wx", w3NameSpace);
xa.Value = "http://schemas.microsoft.com/office/word/2003/2/auxHint";
root.Attributes.Append(xa);
xa = doc.CreateAttribute("xmlns", "o", w3NameSpace);
xa.Value = "urn:schemas-microsoft-com:office:office";
root.Attributes.Append(xa);
xa = doc.CreateAttribute("xmlns", "dt", w3NameSpace);
xa.Value = "uuid:C2F41010-65B3-11d1-A29F-00AA00C14882";
root.Attributes.Append(xa);
xa = doc.CreateAttribute("xmlns", "space", w3NameSpace);
xa.Value = "preserve";
root.Attributes.Append(xa);
//為節(jié)點(diǎn)增加值
System.Xml.XmlNode body = doc.CreateNode(System.Xml.XmlNodeType.Element, "v", "body", "urn:schemas-microsoft-com:vml");
System.Xml.XmlNode childNode = doc.CreateNode(System.Xml.XmlNodeType.Element, "o", "t", "urn:schemas-microsoft-com:office:office");
childNode.InnerText = "歡迎光臨【孟憲會(huì)之精彩世界】";
//添加到內(nèi)存樹(shù)中
body.AppendChild(childNode);
root.AppendChild(body);
doc.AppendChild(root);
//添加節(jié)點(diǎn)聲明
System.Xml.XmlDeclaration xd = doc.CreateXmlDeclaration("1.0", "UTF-8", "yes");
doc.InsertBefore(xd, doc.DocumentElement);
//添加處理指令
System.Xml.XmlProcessingInstruction spi = doc.CreateProcessingInstruction("mso-application", "progid=\"Word.Document\"");
doc.InsertBefore(spi, doc.DocumentElement);
//查詢節(jié)點(diǎn)
System.Xml.XmlNamespaceManager nsmanager = new System.Xml.XmlNamespaceManager(doc.NameTable);
nsmanager.AddNamespace("w", "http://schemas.microsoft.com/office/word/2003/2/wordml");
nsmanager.AddNamespace("v", "urn:schemas-microsoft-com:vml");
nsmanager.AddNamespace("o", "urn:schemas-microsoft-com:office:office");
System.Xml.XmlNode node = doc.SelectSingleNode("w:wordDocument/v:body/o:t", nsmanager);
Response.Write(node.InnerText);
node.InnerText = "歡迎光臨【孟憲會(huì)之精彩世界】:http://dotnet.aspx.cc/";
//創(chuàng)建CDATA節(jié)點(diǎn)
System.Xml.XmlCDataSection xcds = doc.CreateCDataSection("<a );
node.ParentNode.InsertAfter(xcds, node);
Response.Write(xcds.InnerText);
doc.Save(Server.MapPath("test.xml"));
VB.net
Dim w3NameSpace As String = "http://www.w3.org/2000/xmlns/"
Dim doc As New System.Xml.XmlDocument
'創(chuàng)建根節(jié)點(diǎn)
Dim root As System.Xml.XmlNode = doc.CreateNode(System.Xml.XmlNodeType.Element, "w", "wordDocument", "http://schemas.microsoft.com/office/word/2003/2/wordml")
Dim xa As System.Xml.XmlAttribute
xa = doc.CreateAttribute("xmlns", "v", w3NameSpace)
xa.Value = "urn:schemas-microsoft-com:vml"
root.Attributes.Append(xa)
'為節(jié)點(diǎn)添加屬性
xa = doc.CreateAttribute("xmlns", "w10", w3NameSpace)
xa.Value = "urn:schemas-microsoft-com:office:word"
root.Attributes.Append(xa)
xa = doc.CreateAttribute("xmlns", "SL", w3NameSpace)
xa.Value = "http://schemas.microsoft.com/schemaLibrary/2003/2/core"
root.Attributes.Append(xa)
xa = doc.CreateAttribute("xmlns", "aml", w3NameSpace)
xa.Value = "http://schemas.microsoft.com/aml/2001/core"
root.Attributes.Append(xa)
xa = doc.CreateAttribute("xmlns", "wx", w3NameSpace)
xa.Value = "http://schemas.microsoft.com/office/word/2003/2/auxHint"
root.Attributes.Append(xa)
xa = doc.CreateAttribute("xmlns", "o", w3NameSpace)
xa.Value = "urn:schemas-microsoft-com:office:office"
root.Attributes.Append(xa)
xa = doc.CreateAttribute("xmlns", "dt", w3NameSpace)
xa.Value = "uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
root.Attributes.Append(xa)
xa = doc.CreateAttribute("xmlns", "space", w3NameSpace)
xa.Value = "preserve"
root.Attributes.Append(xa)
'為節(jié)點(diǎn)增加值
Dim body As System.Xml.XmlNode = doc.CreateNode(System.Xml.XmlNodeType.Element, "v", "body", "urn:schemas-microsoft-com:vml")
Dim childNode As System.Xml.XmlNode = doc.CreateNode(System.Xml.XmlNodeType.Element, "o", "t", "urn:schemas-microsoft-com:office:office")
childNode.InnerText = "歡迎光臨【孟憲會(huì)之精彩世界】"
'添加到內(nèi)存樹(shù)中
body.AppendChild(childNode)
root.AppendChild(body)
doc.AppendChild(root)
'添加節(jié)點(diǎn)聲明
Dim xd As System.Xml.XmlDeclaration = doc.CreateXmlDeclaration("1.0", "UTF-8", "yes")
doc.InsertBefore(xd, doc.DocumentElement)
'添加處理指令
Dim spi As System.Xml.XmlProcessingInstruction = doc.CreateProcessingInstruction("mso-application", "progid=""Word.Document""")
doc.InsertBefore(spi, doc.DocumentElement)
'查詢節(jié)點(diǎn)
Dim nsmanager As New System.Xml.XmlNamespaceManager(doc.NameTable)
nsmanager.AddNamespace("w", "http://schemas.microsoft.com/office/word/2003/2/wordml")
nsmanager.AddNamespace("v", "urn:schemas-microsoft-com:vml")
nsmanager.AddNamespace("o", "urn:schemas-microsoft-com:office:office")
Dim node As System.Xml.XmlNode = doc.SelectSingleNode("w:wordDocument/v:body/o:t", nsmanager)
Response.Write(node.InnerText)
node.InnerText = "歡迎光臨【孟憲會(huì)之精彩世界】:http://dotnet.aspx.cc/"
'創(chuàng)建CDATA節(jié)點(diǎn)
Dim xcds As System.Xml.XmlCDataSection = doc.CreateCDataSection("<a )
node.ParentNode.InsertAfter(xcds, node)
Response.Write(xcds.InnerText)
doc.Save(Server.MapPath("test.xml"))
您可能感興趣的文章:
- asp.net下用DataSet生成XML的問(wèn)題
- asp.net下DataSet.WriteXml(String)與(Stream)的區(qū)別
- ASP.NET讀取XML文件4種方法分析
- Asp.Net+XML操作基類(修改,刪除,新增,創(chuàng)建)
- asp.net xml序列化與反序列化
- asp.net(C#) Xml操作(增刪改查)練習(xí)
- asp.net 讀取xml文件里面的內(nèi)容,綁定到dropdownlist中
- asp.net下將Excel轉(zhuǎn)成XML檔的實(shí)現(xiàn)代碼
- asp.net使用DataSet的ReadXml讀取XML文件及Stream流的方法
相關(guān)文章
DataGrid中實(shí)現(xiàn)超鏈接的3種方法
這篇文章介紹了DataGrid中實(shí)現(xiàn)超鏈接的3種方法,有需要的朋友可以參考一下2013-09-09.NET?CORE?鑒權(quán)的實(shí)現(xiàn)示例
本文主要介紹了.NET?CORE?鑒權(quán)的實(shí)現(xiàn)示例,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02ASP.NET文件上傳Upload的實(shí)現(xiàn)方法
這篇文章主要為大家詳細(xì)介紹了ASP.NET文件上傳的實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-11-11ASP.NET三層架構(gòu)詳解 如何實(shí)現(xiàn)三層架構(gòu)
這篇文章主要為大家詳細(xì)介紹了ASP.NET三層架構(gòu),如何實(shí)現(xiàn)三層架構(gòu),本文為大家揭曉,感興趣的小伙伴們可以參考一下2016-05-05asp.net下URL網(wǎng)址重寫(xiě)成.html格式、RSS、OPML的知識(shí)總結(jié)
asp.net下URL網(wǎng)址重寫(xiě)成.html格式、RSS、OPML的知識(shí)總結(jié)...2007-09-09IE10下Gridview后臺(tái)設(shè)置行高不起作用解決方法
GridView1.HeaderStyle.Height=17發(fā)現(xiàn)在IE10 中不起作用,經(jīng)過(guò)反復(fù)測(cè)試修改為e.Row.Cells[0].Height=17即可解決問(wèn)題,有類似問(wèn)題的朋友可以參考下哈2013-04-04