Search code examples
xpathxpath-2.0domxpath

How to get HTML element value which is a attribute value of another HTML element?


I am extracting value of an HTML element attribute. but that attribute itself contains another HTML element inside it. So is there anyway i can extract the HTML element value from that attribute?

Here's the element

<div data-content="<i>10%</i><b>C</b>"></div>

and I am trying to get value which is inside <b>C</b> i.e. C

I have tried the below xpath:

//div/@data-content

Please help is there anyway.


Solution

  • You had a typo in your XML. I assume it's supposed to be:

      <div data-content="<i>10%</i><b>C</b>"></div>>
    

    if so, try this and see if it gets you there:

    substring-after((//div/@data-content),'<b>')