Book.xml
<?xml version= "1.0" encoding= "Utf-8"?> <bookstore>
<book category= "COOKING" > <title lang= "en" >everyday italian</title> <author>giada De Laure ntiis</author> <year>2005</year> <price>30.00</price> </book>
<book category= "Children" > <title lang= "en" >harry potter</title> <author>j K. Rowling</ author> <year>2005</year> <price>29.99</price> </book>
<book category= "WEB" > <title lang= "en" >xquery Kick start</title> <author>james McGovern< ;/author> <author>per bothner</author> <author>kurt cagle</author> <author>Ja Mes linn</author> <author>vaidyanathan nagarajan</author> <year>2003</year> < Price>49.99</price> </book>
<book category= "WEB" > <title lang= "en" >learning xml</title> <author>erik T. Ray</author > <year>2003</year> <price>39.95</price> </book>
</bookstore>
C # code://Determine if there is a value for the title: ' Harry Potter ' node exists
Stopwatch watch = Stopwatch.startnew ();
var xmlDoc2 = new XmlDocument ();
Xmldoc2.load (@ "Book.xml");
var titleTextExpr4 = "/bookstore/book[title= ' Harry Potter ']/title";
var titleTextNodes4 = xmldoc2.selectnodes (TITLETEXTEXPR4);
Console.WriteLine ("XPath expression is/bookstore/book[title= ' Harry Potter ']/title, the number of nodes is:" + titletextnodes4.count);
if (titletextnodes4.count>0)
{
Console.WriteLine ("Title= ' Harry Potter ' node exists");
}
Else
{
Console.WriteLine ("Title= ' Harry Potter ' node does not exist");
}
Watch. Stop ();
Console.WriteLine ("Take times (ms) =" +watch. Elapsedmilliseconds);
Methods of using the XPath language in. NET to determine whether a node value exists in XML