节点asp.net下创建、查询、修改带名称空间的 XML 文件的例子

asp.net空间  时间:2021-03-24  阅读:()

http://taskcn.blog. 163.com/

asp.net下创建、查询、修改带名称空间的XML文件的例子C#string w3NameSpace = "http://www.w3.org/2000/xmlns/";

System.Xml.XmlDocument doc = new System.Xml.XmlDocument() ;

//创建根节点

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) ;

//为节点添加属性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) ;http://taskcn.blog. 163.com/

http://taskcn.blog. 163.com/

//为节点增加值

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 = "欢迎光临";

//添加到内存树中body.AppendChild(childNode) ;root.AppendChild(body) ;doc.AppendChild(root) ;

//添加节点声明

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) ;

//查询节点

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 = "欢迎光临:http://dotnet.aspx.cc/";

//创建CDATA节点

System.Xml.XmlCDataSection xcds = doc.CreateCDataSection("a href='http://dotnet.aspx.cc/' /anode.ParentNode. InsertAfter(xcds, node) ;

Response.Write(xcds. InnerText) ;doc.Save(Server.MapPath("test.xml") ) ;http://taskcn.blog. 163.com/

http://taskcn.blog. 163.com/

VB.net

Dim w3NameSpace As String = "http://www.w3.org/2000/xmlns/"

Dim doc As New System.Xml.XmlDocument

'创建根节点

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.XmlAttributexa = doc.CreateAttribute("xmlns", "v", w3NameSpace)xa.Value = "urn:schemas-microsoft-com:vml"root.Attributes.Append(xa)

'为节点添加属性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)http://taskcn.blog. 163.com/

http://taskcn.blog. 163.com/

'为节点增加值

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 = "欢迎光临"

'添加到内存树中body.AppendChild(childNode)root.AppendChild(body)doc.AppendChild(root)

'添加节点声明

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)

'查询节点

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 = "欢迎光临:http://dotnet.aspx.cc/"

'创建CDATA节点

Dim xcds As System.Xml.XmlCDataSection = doc.CreateCDataSection("a href='http://dotnet.aspx.cc/' /a ")node.ParentNode. InsertAfter(xcds, node)

Response.Write(xcds. InnerText)doc.Save(Server.MapPath("test.xml") )http://taskcn.blog. 163.com/

触碰云高性价20.8元/月,香港云服务器,美国cn2/香港cn2线路,4核4G15M仅115.2元/月起

触碰云怎么样?触碰云是一家成立于2019年的商家。触碰云主营香港/美国 VPS服务器、独立服务器以及免备案CDN。采用的是kvm虚拟构架,硬盘Raid10,Cn2线路,去程电信CN2、移动联通直连,回程三网CN2。最低1核1G带宽1M仅20.8元/月,不过这里推荐香港4核4G15M,香港cn2 gia线路云服务器,仅115.2元/月起,性价比还是不错的。点击进入:触碰云官方网站地址触碰云优惠码:优...

Buyvm:VPS/块存储补货1Gbps不限流量/$2起/月

BuyVM测评,BuyVM怎么样?BuyVM好不好?BuyVM,2010年成立的国外老牌稳定商家,Frantech Solutions旗下,主要提供基于KVM的VPS服务器,数据中心有拉斯维加斯、纽约、卢森堡,付费可选强大的DDOS防护(月付3美金),特色是1Gbps不限流量,稳定商家,而且卢森堡不限版权。1G或以上内存可以安装Windows 2012 64bit,无需任何费用,所有型号包括免费的...

sharktech:老牌高防服务器商,跳楼价,1G独享$70、10G共享$240、10G独享$800

不知道大家是否注意到sharktech的所有服务器的带宽价格全部跳楼跳水,降幅简直不忍直视了,还没有见过这么便宜的独立服务器。根据不同的机房,价格也是不一样的。大带宽、不限流量比较适合建站、数据备份、做下载、做流媒体、做CDN等多种业务。 官方网站:https://www.sharktech.net 付款方式:比特币、信用卡、PayPal、支付宝、西联汇款 以最贵的洛杉矶机器为例,配置表如...

asp.net空间为你推荐
迦南serverasp.net空间谁知道免费的ASP空间企业信息查询系统官网怎么查企业信息是否在网上公示过cuteftpCuteFTP 和FlashFXP是什么软件,有什么功能,怎样使用?sqlserver数据库电脑如何找到sql server数据库重庆400年老树穿楼生长重庆适宜驴生长Joinsql碧海银沙网怎样在碧海银沙网里发布图片?zencart模板zencart里那些目录分别对应MVC设计模式的模型 视图 和控制器呢?无忧代理网无忧考网好不好,为什么注册要输入电话号码,可信度高不高,还有中国公务员考试网,这些网站是不是要收费
互联网域名管理办法 百度云100as php探针 服务器cpu性能排行 服务器怎么绑定域名 主机合租 qq数据库 hnyd 双线主机 北京双线 百度云1t 免费的asp空间 深圳主机托管 上海联通 九零网络 godaddyssl phpinfo godaddy退款 weblogic部署 冰盾ddos防火墙 更多