节点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/

百纵科技(1399元/月)香港CN2站群232IP

湖南百纵科技有限公司是一家具有ISP ICP 电信增值许可证的正规公司,多年不断转型探索现已颇具规模,公司成立于2009年 通过多年经营积累目前已独具一格,公司主要经营有国内高防服务器,香港服务器,美国服务器,站群服务器,东南亚服务器租用,国内香港美国云服务器,以及全球专线业务!活动方案:主营:1、美国CN2云服务器,美国VPS,美国高防云主机,美国独立服务器,美国站群服务器,美国母机。2、香港C...

Krypt($120/年),2vCPU/2GB/60GB SSD/3TB

Krypt这两天发布了ION平台9月份优惠信息,提供一款特选套餐年付120美元(原价$162/年),开设在洛杉矶或者圣何塞机房,支持Windows或者Linux操作系统。ion.kryptcloud.com是Krypt机房上线的云主机平台,主要提供基于KVM架构云主机产品,相对于KT主站云服务器要便宜很多,产品可选洛杉矶、圣何塞或者新加坡等地机房。洛杉矶机房CPU:2 cores内存:2GB硬盘:...

LOCVPS新上日本软银线路VPS,原生IP,8折优惠促销

LOCVPS在农历新年之后新上架了日本大阪机房软银线路VPS主机,基于KVM架构,配备原生IP,适用全场8折优惠码,最低2GB内存套餐优惠后每月仅76元起。LOCVPS是一家成立于2012年的国人VPS服务商,提供中国香港、韩国、美国、日本、新加坡、德国、荷兰、俄罗斯等地区VPS服务器,基于KVM或XEN架构(推荐选择KVM),线路方面均选择国内直连或优化方案,访问延迟低,适合建站或远程办公使用。...

asp.net空间为你推荐
重庆云网科技股份有限公司操作http支持ipad三友网网测是什么意思?pintang目前世界上最稀有、最珍贵的钱币是什么?中国保健养猪网135保健养猪,135天可以出栏吗?400电话查询如何辨别400电话的真伪?qq头像上传失败昨天和今天QQ头像上传失败,是怎么回事?qq头像上传失败QQ头像上传失败是怎么回事站点管理电脑怎么进入管理员模式,怎么联系站点管理员
中国十大域名注册商 域名主机基地 怎么申请域名 vpsio 缓存服务器 国外在线代理 宁波服务器 泉州移动 爱奇艺vip免费试用7天 联通网站 www789 东莞服务器托管 德隆中文网 qq金券 lamp架构 免费网络空间 石家庄服务器 godaddy中文 blaze 天鹰抗ddos防火墙 更多