1. some specific name: xmldocument xmlnodelist xmlnode xmlelement
the whole architecture and Relation among them is following
attentions: selectsinglenodelist ("users "), obtains all direct subnodes under users. This method is often used
2. the difference between xmlnode and xmlelement
xmlelement inherits from xmlnode and has the same functions, but xmlelement has more functions
3. insert data into XML file sample:
sample 1:
xmldocument xdoc = new xmldocument ();
xdoc. load (httpcontext. current. server. mappath ("user. config ");
Xmlelement xde = xdoc. documentelement;
Xmlelement Xe = xdoc. createelement ("user ");
Xe. setattribute ("login", login );
Xe. setattribute ("password", PWD );
Xe. setattribute ("rootfolder", rootfolder );
Xe. setattribute ("rights", rights );
Xde. appendchild (xe );
Xdoc. Save (httpcontext. Current. server. mappath ("user. config "));
The XML file is the following
<? XML version = "1.0" standalone = "yes"?>
<Users>
<User Login = "sanxumei" Password = "sanxumei" rootfolder = "C: \ Inetpub \ wwroot" Rights = "user"/>
</Users>
Sample 2:
Xmldocument xmldoc = new xmldocument ();
Xmldoc. Load ("Bookstore. xml ");
Xmlnode root = xmldoc. selectsinglenode ("Bookstore"); // query <bookstore>
Xmlelement xe1 = xmldoc. createelement ("book"); // create a <book> node
Xe1.setattribute ("genre", "lizan red"); // you can specify the genre attribute of the node.
Xe1.setattribute ("ISBN", "2-3631-4"); // you can specify the ISBN attribute of the node.
Xmlelement xesub1 = xmldoc. createelement ("title ");
Xesub1.innertext = "Cs from entry to entry"; // set a text node
Xe1.appendchild (xesub1); // Add it to the <book> node
Xmlelement xesub2 = xmldoc. createelement ("author ");
Xesub2.innertext = "Hou Jie ";
Xe1.appendchild (xesub2 );
Xmlelement xesub3 = xmldoc. createelement ("price ");
Xesub3.innertext = "58.3 ";
Xe1.appendchild (xesub3 );
Root. appendchild (xe1); // Add it to the <bookstore> node
Xmldoc. Save ("Bookstore. xml ");