The XML XML file format is as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<userdata createuser= "false" >
<dataconnection>
<server>localhost</server>
<uid>sa</uid>
<pwd></pwd>
</dataconnection>
<net>
<name>jiayuan</name>
</net>
</userdata>
Read a property in the node
XmlDocument doc=new XmlDocument ();
Doc. Load ("Config.xml"),//Can be added to the path: such as D:\config.xml
XmlNode Xnuser=doc. selectSingleNode ("UserData");
String Flag=xnuser. attributes["CreateUser"]. InnerText;
Reading values in a node
XmlDocument doc=new XmlDocument ();
Doc. Load ("Config.xml");
XmlNode xnserver = doc. selectSingleNode ("Userdata/dataconnection/server");
Modifying the properties of a node
XmlDocument doc=new XmlDocument ();
Doc. Load ("Config.xml");
XmlNode Xnuser=doc. selectSingleNode ("UserData");
Xnuser. attributes["CreateUser"]. Innertext= "false";
Doc. Save ("Config.xml");
Append node
XmlDocument doc = new XmlDocument ();
XmlTextReader reader = new XmlTextReader ("Config.xml");
Doc. Load ("Config.xml");
XmlElement root = Doc. DocumentElement; Get root node
XmlElement tagmessage = doc. createelement ("net");
XmlElement tagtext = doc. createelement ("name");
Tagtext.innertext = NetName;
Tagmessage.appendchild (Tagtext); Append to the last side of XML text
Root. AppendChild (Tagmessage);
Reader. Close (); Close XmlTextReader
Doc. Save ("Config.xml"); Save XML file
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.