XML simple operation-XSL

Source: Internet
Author: User

 

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

 

 

 

 

 

 

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.