0
votes

I have an XPath

//*[@class]

I would like to make an XPath to select the content inside this attribute.

<li class="tab-off" id="navList0">

So in this case I would like to extract the text "tab-off", is this possible with XPath?

2
I have tried //*[@class]/@class it works perfectly.blakepeterman

2 Answers

1
votes

Your original //*[@class] XPath query returns all elements which have a class attribute. What you want is //*[@class]/@class to retrieve the attribute itself.

In case you just want the value and not the attribute name try string(//*[@class]/@class) instead.

0
votes

If you are specifically grabbing the data from an

  • tag, you can do this:
    //li[@class]
    

    and loop through the result set to find a class with attribute "tab-off". Or

    //li[@class='tab-off']
    

    If you're in a position to hard code.

    I assume you have already put your file through an XML parser like a DOMParser. This will make it much easier to extract any other values you may need on a specific tag.