Get the node value in the XML file with the XmlDocument object in C #

Source: Internet
Author: User

XML file:

<?xml version= "1.0" encoding= "Utf-8"?>
<bookstore>
<book>
<title lang= "Eng" >harry potter</title>
<price>29.99</price>
</book>
<book>
<title lang= "Eng" >learning xml</title>
<price>39.98</price>
</book>
<bookstore>
<title lang= "Eng" >learning c#</title>
<price>55.23</price>
</bookstore>
<item name= "1" > First item</item>
<item name= "2" >
<item name= "1" > This node (1) </item>
<item name= "2" > This node (2) </item>
<book>
<title lang= "cn" >learning c</title>
<price>60.95</price>
</book>
</item>
</bookstore>

XmlDocument xdoc = new XmlDocument ();
Xdoc. Load (Server.MapPath ("books.xml"));
XmlNodeList XNL = Xdoc. SelectNodes ("/bookstore/book");
String nodetempstr = "";
foreach (XmlNode node in xnl)
{
NODETEMPSTR = node. InnerText;
NODETEMPSTR = node. selectSingleNode ("title"). InnerText;
NODETEMPSTR = node. Childnodes[0]. InnerText;
}
XmlNodeList Xnodel = Xdoc. SelectNodes ("/bookstore/item[@name = ' 2 ']/item");
XmlNode xnode = Xdoc. selectSingleNode ("/bookstore/item[@name = ' 2 ']/item[@name = ' 2 ']");
XmlNodeList Xnode1 = Xdoc. SelectNodes ("/bookstore/book[price>31]");
String nodetext = XNode. Childnodes[0]. InnerText;

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.