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;
用方法
野草云服务商在前面的文章中也有多次提到,算是一个国内的小众服务商。促销活动也不是很多,比较专注个人云服务用户业务,之前和站长聊到不少网友选择他们家是用来做网站的。这不看到商家有提供香港云服务器的优惠促销,可选CN2、BGP线路、支持Linux与windows系统,支持故障自动迁移,使用NVMe优化的Ceph集群存储,比较适合建站用户选择使用,最低年付138元 。野草云(原野草主机),公司成立于20...
LOCVPS发布了7月份促销信息,全场VPS主机8折优惠码,续费同价,同时香港云地/邦联机房带宽免费升级不加价,原来3M升级至6M,2GB内存套餐优惠后每月44元起。这是成立较久的一家国人VPS服务商,提供美国洛杉矶(MC/C3)、和中国香港(邦联、沙田电信、大埔)、日本(东京、大阪)、新加坡、德国和荷兰等机房VPS主机,基于XEN或者KVM虚拟架构,均选择国内访问线路不错的机房,适合建站和远程办...
陆零网络是正规的IDC公司,我们采用优质硬件和网络,为客户提供高速、稳定的云计算服务。公司拥有一流的技术团队,提供7*24小时1对1售后服务,让您无后顾之忧。我们目前提供高防空间、云服务器、物理服务器,高防IP等众多产品,为您提供轻松上云、安全防护 为核心数据库、关键应用系统、高性能计算业务提供云端专用的高性能、安全隔离的物理集群。分钟级交付周期助你的企业获得实时的业务响应能力,助力核心业务飞速成...