2 small functions of reading and writing XML files (refer to others, slut more)

xiaoxiao2021-03-05  31

#Region reads and writes 2 small functions for XML files, 2005 4 2 by HYC

public void SetXmlFileValue (string xmlPath, string AppKey, string AppValue) // write XMLPath file path file name, AppKey is Key Name, AppValue is Value {XmlDocument xDoc = new XmlDocument (); xDoc.Load (xmlPath); XmlNode xNode XMLELEMENT Xelem1; XMLELEMENT Xelem2;

XNode = xdoc.selectsinglenode ("// appsettings");

Xelem1 = (XMLELEMENT) XNode.selectsinglenode ("// add [@ key = '" appkey "']"); if (Xelem1! = null) {Xelem1.setttribute ("Value", appValue;} else { Xelem2 = xdoc.createElement ("add"); Xelem2.SetaTRibute ("key", appkey); Xelem2.SetAttribute ("Value", appValue; xnode.appendchild (xlem2);} xdoc.save (xmlpath);}

public void GetXmlFileValue (string xmlPath, string AppKey, ref string AppValue) // read XMLPath file path file name, AppKey is Key Name, AppValue is Value {XmlDocument xDoc = new XmlDocument (); xDoc.Load (xmlPath); XmlNode XNode; XMLELEMENT Xelem1;

XNode = xdoc.selectsinglenode ("// appsettings");

Xelem1 = (XMLELEMENT) xNode.selectsinglenode ("// add [@ key = '" appkey ""); if (Xelem1! = null) {appValue = Xelem1.GetaTribute ("value");} else} // MessageBox.show ("there is not anyournal!");

}

#ndregion

转载请注明原文地址:https://www.9cbs.com/read-34155.html

New Post(0)