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

用方法

ShineServers(5美元/月)荷兰VPS、阿联酋VPS首月五折/1核1G/50GB硬盘/3TB流量/1Gbps带宽

优惠码50SSDOFF 首月5折50WHTSSD 年付5折15OFF 85折优惠,可循环使用荷兰VPSCPU内存SSD带宽IPv4价格购买1核1G50G1Gbps/3TB1个$ 9.10/月链接2核2G80G1Gbps/5TB1个$ 12.70/月链接2核3G100G1Gbps/7TB1个$ 16.30/月链接3核4G150G1Gbps/10TB1个$ 18.10/月链接阿联酋VPSCPU内存SS...

pigyun25元/月,香港云服务器仅起;韩国云服务器,美国CUVIP

pigyun怎么样?PIGYun成立于2019年,2021是PIGYun为用户提供稳定服务的第三年,期待我们携手共进、互利共赢。PIGYun为您提供:香港CN2线路、韩国CN2线路、美西CUVIP-9929线路优质IaaS服务。月付另有通用循环优惠码:PIGYun,获取8折循环优惠(永久有效)。目前,PIGYun提供的香港cn2云服务器仅29元/月起;韩国cn2云服务器仅22元/月起;美国CUVI...

可抵御99%的攻击中国单域版cdn:9元/月7T防御 cloudsecre

官方网站:点击访问CDN客服QQ:123008公司名:贵州青辞赋文化传媒有限公司域名和IP被墙封了怎么办?用cloudsecre.com网站被攻击了怎么办?用cloudsecre.com问:黑客为什么要找网站来攻击?答:黑客需要找肉鸡。问:什么是肉鸡?答:被控的服务器和电脑主机就是肉鸡。问:肉鸡有什么作用?答:肉鸡的作用非常多,可以用来干违法的事情,通常的行为有:VPN拨号,流量P2P,攻击傀儡,...

c xml为你推荐
支付宝查询余额我的支付宝如何查询余额1433端口1433端口怎么打开arm开发板ARM开发板具体有什么作用?有什么商业价值?神雕侠侣礼包大全神雕侠侣手游每天送的元宝买什么合适商标注册查询官网怎么查商标有没有注册bluestackbluestacks安卓模拟器有什么用宽带接入服务器目前常见宽带接入的方式有哪几种如何清理ie缓存怎么清理IE缓存网站地图制作网站地图 怎么制作?首页无法修改默认主页无法修改怎么办?
fc2最新域名 photonvps asp.net主机 l5520 名片模板psd NetSpeeder 青果网 上海域名 anylink 有益网络 网站木马检测工具 双12 万网空间管理 双线空间 万网主机 后门 深圳主机托管 japanese50m咸熟 建站技术 globalsign 更多