Reputation: 23
<test>
<child id="13680621263370126043"/>
<child id="13680621263370124329"/>
</test>
Code:
doc.SelectNodes(@"/test/child[@Id=13680621263370126043]");
the returned list has both child nodes in it, what gives?
Upvotes: 2
Views: 50
Reputation: 111726
Change
/test/child[@Id=13680621263370126043]
to
/test/child[@id='13680621263370126043']
because
XPath uses double-precision 64-bit format IEEE 754 value for numbers, which has 15-17 signicant decimal digits. The @id
attribute here has 20 digits and therefore must be tested as a string, not as a number.
Upvotes: 2
Reputation: 37281
You have 2 problems:
id
and not Id
.''
So:
var doc = new XmlDocument();
doc.Load("data.xml");
var result = doc.SelectNodes(@"//test/child[@id='13680621263370126043']");
// result contains 1 item
Upvotes: 2