I have two queries that appear to be exactly the same, but one of them
returns null while the other one returns a valid result!
Can anyone provide an explanation to why this is so? Below is an nunit
test that exposes the problem. I have run the test under both the 1.0
and 1.1 framework with the same result.
[Test]
public void XPathBooks()
{
XmlDocument smallDoc = new XmlDocument();
smallDoc.LoadXml("<book><title>Bugs</title></book>");
XmlNode book1 = smallDoc.SelectSingleNode(@"book");
XmlNode title1 = book1.SelectSingleNode(@"/book/title");
Assert.IsNotNull(title1, "title1");
XmlDocument largeDoc = new XmlDocument();
largeDoc.LoadXml("<books><book><title>Bugs</title></book></books>");
XmlNode book2 = largeDoc.SelectSingleNode(@"books/book");
Assert.AreEqual(book1.OuterXml, book2.OuterXml);
XmlNode title2 = book2.SelectSingleNode(@"/book/title");
Assert.IsNotNull(title2, "title2"); // This test fails!!
}
Thanks,
Rune