1

I'm totally new to XPath and need to use it for a project. My XML looks like

<AverageErrorRate>
    <float>0123</float>
    <float>0456</float>
</AverageErrorRate>

I'm using this site: http://www.xpathtester.com/xpath

When I try to do:

/AverageErrorRate/float[0]

It just returns the same thing to me. But if I do

/AverageErrorRate/float[1]

Then I get 0123 which is what I want. Am I missing something about the way XPath works?

halfer
  • 19,824
  • 17
  • 99
  • 186
Crystal
  • 28,460
  • 62
  • 219
  • 393
  • related: https://stackoverflow.com/questions/3319341/why-do-indexes-in-xpath-start-with-1-and-not-0 –  Feb 13 '15 at 19:16

1 Answers1

1
/AverageErrorRate/float[0]

is not returning the same thing, it returns nothing.

INFO - XPath returned 0 items

Indexes in XPath start at 1, therefore the website is correct.

Also note that you're not getting 0123, you're getting <float>0123</float>, which is the whole element. If you want the text only, use

/AverageErrorRate/float[1]/text()
Thomas Weller
  • 55,411
  • 20
  • 125
  • 222