c# vs xml
i'm sorry for my bad english.
i'm an italian student and i've a problem with the execution of a xpath expression.
i've a document named book.xml in C:\
and i don't know for what reason this code i wrote doesn't work:
------------------------------------------------------------------------------
XmlTextReader reader = new XmlTextReader(@"c:\book.xml");
XmlDocument doc = new XmlDocument();
doc.Load(reader);
XmlNodeList nodeList;
XmlElement root = doc.DocumentElement;
// nodeList = root.SelectNodes("/bookstore/book/price[text()>'9.00']"); <-- this query works
nodeList = root.SelectNodes("/bookstore/book/price[text()='11.99']"); // <-- this query doesn't work
Console.Write(nodeList.Count.ToString());
---------------------------------------------------------------------------
this is the structure of book.xml
bookstore
book
price 11.99 /price
author .. author
title .. /title
/book
...other books
/bookstore
if i can't solve this problem my work doesn't go on :(
gino ginoPosted Nov 11, 2005, 2:49 PM
there was an error in the xml file, not in the code ehehehe...i'm too much stupid!!!
joePosted Nov 11, 2005, 11:12 AM
If this is your Xml structure:
There's nothing wrong with your code. I'd maybe drop the use of the XmlTextReader though:
XmlDocument doc =
new XmlDocument();doc.Load(@"c:\book.xml");
XmlNodeList nodeList;
XmlElement root = doc.DocumentElement;
nodeList = root.SelectNodes("/bookstore/book/price[text()>'9.00']"); // <-- this query works
//nodeList = root.SelectNodes("/bookstore/book/price[text()='11.99']"); // <-- this query works too
Console.Write(nodeList.Count.ToString());
Console.ReadLine();
Joe