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

俄罗斯vps主机推荐,怎么样俄罗斯vps俄罗斯vps速度怎么样?

俄罗斯vps速度怎么样?俄罗斯vps云主机节点是欧洲十大节点之一,地处俄罗斯首都莫斯科,网络带宽辐射周边欧洲大陆,10G专线连通德国法兰克福、法国巴黎、意大利米兰等,向外连接全球。俄罗斯vps云主机速度快吗、延迟多少?由于俄罗斯数据中心出口带宽充足,俄罗斯vps云主机到全球各地的延迟、速度相对来说都不错。今天,云服务器网(yuntue.com)小编介绍一下俄罗斯vps速度及俄罗斯vps主机推荐!俄...

Dynadot COM特价新注册48元

想必我们有一些朋友应该陆续收到国内和国外的域名注册商关于域名即将涨价的信息。大概的意思是说从9月1日开始,.COM域名会涨价一点点,大约需要单个9.99美元左右一个。其实对于大部分用户来说也没多大的影响,毕竟如今什么都涨价,域名涨一点点也不要紧。如果是域名较多的话,确实增加续费成本和注册成本。今天整理看到Dynadot有发布新的八月份域名优惠活动,.COM首年注册依然是仅需48元,本次优惠活动截止...

麻花云:3折优惠,香港CN2安徽麻花云香港安徽移动BGP云服务器(大带宽)

麻花云在7月特意为主机测评用户群定制了促销活动:香港宽频CN2云服务器、安徽移动云服务器(BGP网络,非单线,效果更好)、安徽移动独立服务器、安徽电信独立服务器,全部不限制流量,自带一个IPv4,默认5Gbps的DDoS防御。活动链接:https://www.mhyun.net/act/zjcp特价云服务器不限流量,自带一个IPv4,5Gbps防御香港宽频CN2全固态Ⅲ型 4核4G【KVM】内存:...

asp.net空间为你推荐
请阅读最后一页信息披露和重要声明采购iphoneapple.com.cn苹果官方网址到底是http://store.apple.com/cn/?还是 http://www.apple.com.cn????magentomagento是免费的吗?wordpress模板我在wordpress模板下载了一套模板,做了www.xuanqianbao.com这个站,模板的原站是www.rrzdm.com.一样的模板,我在文件在插入图片,却不能在首页显示,他的网站却可以.直字节跳动回应TikTok易主抖音字节跳动是什么意思?申请支付宝账户申请支付宝账号注册加多宝和王老吉加多宝和王老吉什么关系 王老吉和加多宝哪个正宗zhuo爱作文:温暖的( )青岛网通测速中国联通宽带,青岛地区咋样,与网通有啥区别
域名备案收费吗 万网域名管理 注册cn域名 西安电信测速 BWH 一元域名 牛人与腾讯客服对话 数字域名 789电视 360云服务 视频服务器是什么 中国linux 免费网络 阿里云邮箱登陆地址 godaddy空间 腾讯数据库 新疆服务器 tracker服务器 xshell5注册码 websitepanel 更多