Grackel1234 Grackel1234 - 1 month ago 7
C# Question

Why does this XPath filter not work (maximum number)?

<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?

Answer

Change

 /test/child[@Id=13680621263370126043]

to

 /test/child[@id='13680621263370126043']

because

  1. XML is case-sensitive.
  2. The value being tested is too long to be tested as a number.

Note on maximum numbers in XPath

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.