1. Special symbol input in XML;
& Lt; <less
& Gt;> greater
& Amp; & and number
& Apos; 'single quotes
& Quot; "quotation marks
2. Read XML files (load XML)
Xmldocument Doc = new xmldocument ();
Doc. Load (file. openread (server. mappath ("textread1.xml ")));
3. Save XML
Doc. saveas (server. mappath ("Doc. xml "));
Doc. Save ("Doc. xml ");
4. Get the node Value
Doc. selectsinglenode ("PNET/data/domatter"). childnodes [0]. attributes [0]. value;
Doc. selectsinglenode ("PNET/data/domatter"). Attributes. getnameditem ("value1"). value;
}
Doc. selectsinglenode ("PNET/data/domatter"). Attributes. getnameditem ("name"). value;
5. add nodes and set node values
Xmlnode node = Doc. selectsinglenode ("Node ");
Xmlelement newnode = Doc. createelement ("newnode ");
Node. appendchild (newnode );
Newnode. setattribute ("name", (string) value );
6. Modify node values
Xmlnode node = Doc. selectsinglenode ("data ");
Xmlelement Xe = (xmlelement) node;
If (Xe. getattribute ("name") = value)
Xe. setattribute ("value1", (string) newvalue );
If (Xe. Name = "value ")
Xe. innertext = newvalue;
7. delete a subnode
Xe. removeattribute ("name"); delete an attribute named name
Xe. removeall (); Delete all content in the node
8. Traverse subnodes
Foreach (xmlnode Xn in DOC ){
Xmlelement Xe = (xmlelement) xn;
}
Xmlnodelist xnl = Xe. childnodes;
Foreach (xmlnode xnn in xnl ){
Xmlelement xee = (xmlelement) xnn;
}
XML can be seen as a web page, and XSL can be seen as a CSS style table, but it must be accurate to every element.
P3.xml content
<? XML version = "1.0" encoding = "gb2312"?>
<? XML-stylesheet type = "text/XSL" href = "p3.xsl"?>
<Books>
<Book>
<Name> the C ++ standard library </Name>
<Author> niclai M. josutis </author>
</Book>
<Book>
<Name> The Mythical man-month </Name>
<Author> Frederick P Brooks Jr. </author>
</Book>
<Book>
<Name> C # design pattern </Name>
<Author> James W. Cooper </author>
</Book>
</Books>
P3.xsl content
<? XML version = "1.0" encoding = "gb2312"?>
<XSL: stylesheet xmlns: XSL = "http://www.w3.org/TR/WD-xsl">
<XSL: template match = "/">
<HTML>
<Head> <title> book store </title> <Body>
<XSL: Apply-templates select = "books"/>
</Body>
</Html>
</XSL: Template>
<XSL: template match = "books">
<Table border = "1" cellpadding = "0" align = "center">
<Tr bgcolor = "red"> <TH> name </Th> <TH> author </Th> </tr>
<XSL: For-each select = "book">
<Tr>
<TD> <XSL: value-of select = "name"/> </TD>
<TD> <XSL: value-of select = "author"/> </TD>
</Tr>
</XSL: For-each>
</Table>
</XSL: Template>
</XSL: stylesheet>
Effect credit 1.jpg