Skip to content

C# vs xml

gino gino

Asked Nov 10, 2005, 6:16 AM EST2 answers
Share
LinkedInX
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 :(

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Well first off, there's nothing wrong with your English!

    If this is your Xml structure:

    <bookstore>
     <book>
      <price>11.99</price>
      <author>Author One</author>
      <title>Book One</title>
     </book>
     <book>
      <price>12.99</price>
      <author>Author Two</author>
      <title>Book Two</title>
     </book>
    </bookstore>

    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

    0
  • 0

    there was an error in the xml file, not in the code ehehehe...i'm too much stupid!!!

    0