插入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;

用方法

lcloud零云:沪港IPLC,70元/月/200Mbps端口/共享IPv4/KVM;成都/德阳/雅安独立服务器低至400元/月起

lcloud怎么样?lcloud零云,UOVZ新开的子站,现在沪港iplc KVM VPS有端午节优惠,年付双倍流量,200Mbps带宽,性价比高。100Mbps带宽,500GB月流量,10个,512MB内存,优惠后月付70元,年付700元。另有国内独立服务器租用,泉州、佛山、成都、德阳、雅安独立服务器低至400元/月起!点击进入:lcloud官方网站地址lcloud零云优惠码:优惠码:bMVbR...

ftlcloud(超云)9元/月,1G内存/1核/20g硬盘/10M带宽不限/10G防御,美国云服务器

ftlcloud怎么样?ftlcloud(超云)目前正在搞暑假促销,美国圣何塞数据中心的云服务器低至9元/月,系统盘与数据盘分离,支持Windows和Linux,免费防御CC攻击,自带10Gbps的DDoS防御。FTL-超云服务器的主要特色:稳定、安全、弹性、高性能的云端计算服务,快速部署,并且可根据业务需要扩展计算能力,按需付费,节约成本,提高资源的有效利用率。点击进入:ftlcloud官方网站...

免费注册宝塔面板账户赠送价值3188礼包适合购买抵扣折扣

对于一般的用户来说,我们使用宝塔面板免费版本功能还是足够的,如果我们有需要付费插件和专业版的功能,且需要的插件比较多,实际上且长期使用的话,还是购买付费专业版或者企业版本划算一些。昨天也有在文章中分享年中促销活动。如今我们是否会发现,我们在安装宝塔面板后是必须强制我们登录账户的,否则一直有弹出登录界面,我们还是注册一个账户比较好。反正免费注册宝塔账户还有代金券赠送。 新注册宝塔账户送代金券我们注册...

c xml为你推荐
万维读者网万维书刊投稿有稿费么,有的话怎么算?快递打印快递单上是怎么打印上去的,我每次都是手写的伪装微信地理位置用软件 伪装微信地理位置 在相册上传图片显示所在城市还是我目前的位置?如何免费开通黄钻怎么免费开通黄钻1433端口路由器1433端口怎么开启镜像文件是什么什么是镜像文件啊办公协同软件最好用的协同办公软件是哪个奇虎论坛奇虎论坛最新推荐歌曲列表·bt封杀为什么现在网上许多BT下载都被封了?bluestackbluestacks安卓模拟器有什么用
域名转让网 网站备案域名查询 美国主机排名 七牛优惠码 华为云服务 softlayer vpsio 云图标 商家促销 台湾谷歌网址 ibox官网 godaddy域名证书 阿里云浏览器 hostloc 泉州电信 免费防火墙 789电视剧 我的世界服务器ip 免费asp空间申请 日本代理ip 更多