1

I'm totally noob 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? Thanks in advance!

Crystal
  • 27,012
  • 59
  • 215
  • 378

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
  • 49,619
  • 19
  • 114
  • 198