Get XML node value

Source: Internet
Author: User

<?XML version= ' 1.0 '?><!-–this file represents a fragment of a book store inventory database-–><Bookstore>   < Bookgenre= "Autobiography"publicationdate= "1991"ISBN= "1-861003-11-0">      <title>The Autobiography of Benjamin Franklin</title>      <author>         <First-name>Benjamin</First-name>         <Last-name>Franklin</Last-name>      </author>      < Price>8.99</ Price>   </ Book>   < Bookgenre= "novel"publicationdate= "1967"ISBN= "0-201-63361-2">      <title>The Confidence Mans</title>      <author>         <First-name>Herman</First-name>         <Last-name>Melville</Last-name>      </author>      < Price>11.99</ Price>   </ Book>   < Bookgenre= "Philosophy"publicationdate= "1991"ISBN= "1-861001-57-6">      <title>The Gorgias</title>      <author>         <name>Plato</name>      </author>      < Price>9.99</ Price>   </ Book></Bookstore>

Today through debugging find out how XML reads different nodes worthwhile method

First get the book node

XmlDocument doc = new XmlDocument ();            Doc. Load (System.Web.HttpContext.Current.Server.MapPath ("books.xml"));            XmlNodeList nodelist = doc. getElementsByTagName ("bool");            list<string> genre = new list<string> ();            list<string> title = new List<string> ();            foreach (XmlNode node in nodelist)            {                //Gets the value genre of the genre element within the book node                        . ADD (node. attributes["Genre"]. Value);                Title. ADD (node. Childnodes[0]. InnerText);            }    

Now also figure out, 2 different, corresponding to 2 extraction methods

Node. attributes["Genre"]. Value;node. Childnodes[0]. InnerText;

Get XML node value

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.