1

So I have an xml file that is formatted something like this

<TopXmlTree>
    <IndentedItem1>
        <subvalue1>
        <subvalue2>
        <subvalue3>
    <IndentedItem1> (Same name as above but a different subset)
        <subvalue1>
        <subvalue2>
        <subvalue3> <<-- I want to get this value

Let's assume that I wanted to get the value above, is there any way that I can do that with Xpath? Normally my Xpath Code is something simple like

XPathExpression expr = xpath.compile("/TopXmlTree/IndentedItem1/Subvalue1/text()");

Which I clearly can't do given the circumstances.

Thanks!

A_Elric
  • 3,508
  • 13
  • 52
  • 85
  • [Similar post](http://stackoverflow.com/questions/3674569/how-to-select-specified-node-within-xpath-node-sets-by-index-with-selenium) to find the nth child. See the answer from Dimitre Novatchev which is not the accepted answer. It may help you – Brad May 17 '12 at 14:44

1 Answers1

2

You need to get the subvalue3 value of the second IndentedItem1 subset so it would look like something like this:

XPathExpression expr = xpath.compile("//TopXmlTree/IndentedItem1[2]/subvalue3/text()");

dukable
  • 3,968
  • 11
  • 31
  • 42