<?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