插入xml文档操作类c

c xml  时间:2021-02-14  阅读:()

xml文档操作C#objXmlDoc.AppendChild(objXmlDoc.CreateXmlDeclaration( 1.0,utf-8 ,null));//置xml的版本格式信息objXmlDoc.AppendChild(objXmlDoc.CreateElement( , sRoot, ));//建根元素objXmlDoc.Save(XmlFile);//保存else//否 文件是否存在 不存在 建if(!(File.Exists(XmlFile)))objXmlDoc.AppendChild(objXmlDoc.CreateXmlDeclaration( 1.0,utf-8,null));objXmlDoc.AppendChild(objXmlDoc.CreateElement( , sRoot, ));objXmlDoc.Save(XmlFile);objXmlDoc.Load(XmlFile);catch(System.Exception ex)throw ex;strXmlFile=XmlFile;

///param name=XmlPathNode xPath /param

///returns有数据返回DataView 否返回null/returnspublic DataView GetData(string XmlPathNode)

//找数据。返回一个D ataVi ew

DataSet ds=new DataSet();try

StringReader read = newStringReader(objXmlDoc.SelectSingleNode(XmlPathNode).OuterXml);ds.ReadXml(read);

return ds.Tables[0].DefaultView;c atch

//throw;return null;

///summary

///更新点内容

////summary

///param name=xmlPathNode/param

///param name=content/parampublic void UpdateNode(string xmlPathNode, string content)objXmlDoc.SelectSingleNode(xmlPathNode).InnerText=content;

///summary

///更新点的某个属性

////summary

///param name=xmlPathNode要操作的点/param

///p aram name=AttribName属性名/p aram

///param name=AttribValue属性 /parampublic void UpdateNode(string xmlPathNode, string AttribName, string AttribValue)

((XmlElement)(objXmlDoc.SelectSingleNode(xmlPathNode))).SetAttribute(AttribName,AttribValue);

///param name=xmlPathNode要操作点的xpath句/param

///p aram name=arrAttribName属性名称字符串数 /p aram

///p aram name=arrAttrib Content属性内容字符串数 /param

///param name=content 点内容/parampublic void UpdateNode(string xmlPathNode, string[] arrAttribName, string[] arrAttribContent,string content)

XmlNode xn=objXmlDoc.SelectSingleNode(xmlPathNode);if(xn!=null)xn.InnerText=content;xn.Attributes.RemoveAll();for(int i=0; i=arrAttribName.GetUpperB ound(0); i++)

((XmlElement)(xn)).S etAttribute(arrAttribName[i],arrAttrib C ontent[i]);

///summary

///移除定点集的所有属性

////summary

///param name=xmlPathNode/parampublic void RemoveAllAttribute(string xmlPathNode)

XmlNodeList xnl=objXmlDoc.SelectNodes(xmlPathNode);foreach(XmlNode xn in xnl)xn.Attributes.RemoveAll();string mainNode=Node.Substring(0,Node.LastIndexOf(/));objXmlDoc.SelectSingleNode(mainNode).RemoveChild(objXmlDoc.SelectSingleNode(Node));c atch

//throw;

r e turn;public void InsertNodeWithChild(string mainNode, string ChildNode, string Element, stringContent)

//插入一点和此点的一子点。

XmlNode objRootNode=objXmlDoc.SelectSingleNode(mainNode);

XmlElement obj ChildNode=objXmlDoc.CreateElement(ChildNode);objRootNode.AppendChild(obj ChildNode);//插入点

XmlElement objElement=objXmlDoc.CreateElement(Element);obj Element.InnerText=Content;obj ChildNode.AppendChild(objElement);//插入子点

///summary

///插入一个点 一个Attribute和innerText

////summary

///param name=mainNode/param

///param name=Element 点名称/param

///p aram name=Attrib Attribute名称/param

///param name=Attrib Content Attribute /param

///param name=Content innerText /parampublic void InsertNode(string mainNode, string Element, string Attrib, string AttribContent,string Content)

XmlNode objNode=objXmlDoc.SelectSingleNode(mainNode);

XmlElement objElement=objXmlDoc.CreateElement(Element);obj Element.S etAttribute(Attrib,Attrib Content);

obj Element.InnerText=Content;objNode.AppendChild(objElement);

///summary

///插入一个点 一个Attrib ute

////summary

///param name=mainNode/param

///param name=Element 点名称/param

///p aram name=Attrib Attribute名称/param

///param name=Attrib Content Attribute /parampublic void InsertNode(string mainNode, string Element, string Attrib, string AttribContent)XmlNode objNode=objXmlDoc.SelectSingleNode(mainNode);

XmlElement objElement=objXmlDoc.CreateElement(Element);obj Element.S etAttribute(Attrib,Attrib Content);objNode.AppendChild(objElement);

///param name=Element 点名称/parampublic void InsertNode(string mainNode, string Element)

XmlNode objNode=objXmlDoc.SelectSingleNode(mainNode);

XmlElement objElement=objXmlDoc.CreateElement(Element);objNode.AppendChild(objElement);

///summarypublic void InsertNode(string mainNode, string elementName, string[] arrAttributeName,

string[]arrAttributeContent, string elementContent)try

XmlNode objNode=objXmlDoc.SelectSingleNode(mainNode);

XmlElement objElement=objXmlDoc.CreateElement(elementName);for(int i=0; i=arrAttributeName.GetUpperB ound(0); i++)obj Element.S etAttribute(arrAttributeName[i],arrAttribute C ontent[i]);obj Element.InnerText=elementContent;objNode.AppendChild(objElement);c atchthrow;

//string t=mainNode;

//;

///summary

///插入一个点 多个属性

////summarypublic void InsertNode(string mainNode, string elementName, string[] arrAttributeName,string[]arrAttribute Content)try

XmlNode objNode=objXmlDoc.SelectSingleNode(mainNode);

XmlElement objElement=objXmlDoc.CreateElement(elementName);for(int i=0; i=arrAttributeName.GetUpperB ound(0); i++)obj Element.S etAttribute(arrAttributeName[i],arrAttribute C ontent[i]);

//obj Element.InnerText=elementContent;

objNode.AppendChild(objElement);c atchthrow;

//string t=mainNode;

//;

///summary

///插入子点(多个属性)

////summary

///param name=parentNode要插入的父点/param

///param name=elementName插入的点名称/param

///p aram name=arrAttributeName属性名称[数] /p aram

///p aram name=arrAttribute Content属性内容[数] /param

///param name=elementContent 点内容/parampublic void AddChildNode(string parentNodePath, string elementName, string[]arrAttributeName, string[]arrAttributeContent, string elementContent)try

XmlNode parentNode=objXmlDoc.SelectSingleNode(parentNodePath);

XmlElement obj ChildElement=objXmlDoc.CreateElement(elementName);for(int i=0; i=arrAttributeName.GetUpperB ound(0); i++)obj ChildElement.S etAttribute(arrAttributeName[i],arrAttribute Content[i]);obj ChildElement.InnerText=elementContent;parentNode.AppendChild(obj ChildElement);

c atchr e turn;

///summary

///插入子点(将内容以CD ata形式写入)

////summary

///param name=parentNode要插入的父点/param

///param name=elementName插入的点名称/param

///param name=elementContent 点内容/parampublic void AddChildNodeCData(string parentNodePath, string elementName, stringelementContent)try

XmlNode parentNode=objXmlDoc.SelectSingleNode(parentNodePath);

XmlElement obj ChildElement=objXmlDoc.CreateElement(elementName);

//写入cData数据

XmlCDataSection xcds=objXmlDoc.CreateCDataSection(elementContent);obj ChildElement.AppendChild(xcds);parentNode.AppendChild(obj ChildElement);c atchr e turn;

///param name=parentNode要插入的父点/param

///param name=elementName插入的点名称/param

///param name=elementContent 点内容/param

public void AddChildNode(string parentNodePath, string elementName, string elementContent)try

XmlNode parentNode=objXmlDoc.SelectSingleNode(parentNodePath);

XmlElement obj ChildElement=objXmlDoc.CreateElement(elementName);obj ChildElement.InnerText=elementContent;parentNode.AppendChild(obj ChildElement);c atchr e turn;

///summary

///根据xp ath 找点

////summary

///p aram name=NodeP ath要找点的xp ath /p aram

///returns找到返回true,否返回true/returnspublic bool FindNode(string NodePath)tryif(objXmlDoc.SelectSingleNode(NodePath) !=null)return true;elsereturn false;c atchreturn false;

用方法

Pia云服务商春节6.66折 美国洛杉矶/中国香港/俄罗斯和深圳机房

Pia云这个商家的云服务器在前面也有介绍过几次,从价格上确实比较便宜。我们可以看到最低云服务器低至月付20元,服务器均采用KVM虚拟架构技术,数据中心包括美国洛杉矶、中国香港、俄罗斯和深圳地区,这次春节活动商家的活动力度比较大推出出全场6.66折,如果我们有需要可以体验。初次体验的记得月付方案,如果合适再续约。pia云春节活动优惠券:piayun-2022 Pia云服务商官方网站我们一起看看这次活...

日本CN2、香港CTG(150元/月) E5 2650 16G内存 20M CN2带宽 1T硬盘

提速啦简单介绍下提速啦 是成立于2012年的IDC老兵 长期以来是很多入门级IDC用户的必选商家 便宜 稳定 廉价 是你创业分销的不二之选,目前市场上很多的商家都是从提速啦拿货然后去分销的。提速啦最新物理机活动 爆炸便宜的香港CN2物理服务器 和 日本CN2物理服务器香港CTG E5 2650 16G内存 20M CN2带宽 1T硬盘 150元/月日本CN2 E5 2650 16G内存 20M C...

易速互联月付299元,美国独立服务器促销,加州地区,BGP直连线路,10G防御

易速互联怎么样?易速互联是国人老牌主机商家,至今已经成立9年,商家销售虚拟主机、VPS及独立服务器,目前商家针对美国加州萨克拉门托RH数据中心进行促销,线路采用BGP直连线路,自带10G防御,美国加州地区,100M带宽不限流量,月付299元起,有需要美国不限流量独立服务器的朋友可以看看。点击进入:易速互联官方网站美国独立服务器优惠套餐:RH数据中心位于美国加州、配置丰富性价比高、10G DDOS免...

c xml为你推荐
解压程序手机解压软件zarchiver怎么用安装程序配置服务器失败sql server 2000 安装程序配置服务器失败无线路由器限速设置无线路由器限速怎么设置!显卡温度多少正常显卡温度多少正常中小企业信息化信息化为中小企业发展带来了哪些机遇qq空间装扮qq空间的装扮空间在哪?xp系统停止服务XP系统停止服务后电脑怎么办?人人逛街过节了,这儿可真热闹写一段话宕机宕机是什么意思?网站优化方案网站优化方案如何写?
国外永久服务器 10t等于多少g 美国php主机 正版win8.1升级win10 电信网络测速器 lamp什么意思 七牛云存储 hdsky reboot asp简介 傲盾代理 电信测速器在线测网速 卡巴斯基官方下载 cc攻击 vpsaa 29美元 winscpiphone 阿里云主机 国内免备案cdn 大容量存储控制器 更多