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

用方法

wordpress外贸集团企业主题 wordpress高级推广外贸主题

wordpress外贸集团企业主题,wordpress通用跨屏外贸企业响应式布局设计,内置更完善的外贸企业网站优化推广功能,完善的企业产品营销展示 + 高效后台自定义设置。wordpress高级推广外贸主题,采用标准的HTML5+CSS3语言开发,兼容当下的各种主流浏览器,根据用户行为以及设备环境(系统平台、屏幕尺寸、屏幕定向等)进行自适应显示; 完美实现一套主题程序支持全部终端设备,保证网站在各...

物语云-VPS-美国洛杉矶VPS无限流量云windows大带宽100M不限流量 26/月起

物语云计算怎么样?物语云计算(MonogatariCloud)是一家成立于2016年的老牌国人商家,主营国内游戏高防独服业务,拥有多家机房资源,产品质量过硬,颇有一定口碑。本次带来的是特惠活动为美国洛杉矶Cera机房的不限流量大带宽VPS,去程直连回程4837,支持免费安装Windows系统。值得注意的是,物语云采用的虚拟化技术为Hyper-v,因此并不会超售超开。一、物语云官网点击此处进入物语云...

酷番云78元台湾精品CN2 2核 1G 60G SSD硬盘

酷番云怎么样?酷番云就不讲太多了,介绍过很多次,老牌商家完事,最近有不少小伙伴,一直问我台湾VPS,比较难找好的商家,台湾VPS本来就比较少,也介绍了不少商家,线路都不是很好,有些需求支持Windows是比较少的,这里我们就给大家测评下 酷番云的台湾VPS,支持多个版本Linux和Windows操作系统,提供了CN2线路,并且还是原生IP,更惊喜的是提供的是无限流量。有需求的可以试试。可以看到回程...

c xml为你推荐
spgnux思普操作系统怎么样sourcegear请问高手这是什么“dynamsoft sourceanywhere for vss”,做项目的时候用的,我是新手不知道这是干什么。百度抢票浏览器手机百度浏览器抢票版根本就没预约抢票。噱头而已!bluestacksBlueStacks是什么?在PC上畅玩Android 45万款应用中小企业信息化中小企业信息化途径有哪些畅想中国畅想中国发展前景bt封杀BT下载可以封杀迅雷吗?什么原理?能破吗?ios系统iOS系统为什么那么好iphone6上市时间苹果6什么时候出?多少钱blogcnblogcn的博客可以搬家到哪些网站?
免费域名注册 视频空间租用 vps服务器 80vps zpanel 荷兰服务器 directspace fastdomain 线路工具 美国php空间 debian7 php免费空间 我爱水煮鱼 卡巴斯基官方免费版 双线asp空间 西安服务器托管 阿里云免费邮箱 秒杀品 东莞主机托管 iki 更多