'In string which have escape characters, How to get element by useing Xpath?

I have a html like this.

<div id="video1" value="&lt;iframe src=&quot;https://www.move.com/99&quot;&gt;&lt;/iframe&gt;"
class="movie"></div>

I want to get url [ https://www.movie.com/99 ] by useing Xpath.

However, the escape characters and other make it difficult.

How to get it by useing Xpath or other means.



Solution 1:[1]

If you have an escaped XML document within an attribute or text node of an outer document, then the only way you can use XPath to probe into the inner document is to parse it first. In XPath 3.1 you can do

parse-xml(div/@value)/iframe/@src

but that's not possible in older XPath versions.

Solution 2:[2]

An easy approach would be using substring functions like this:

substring-before(substring-after(div[@id='video1' and @class='movie']/@value,'&quot;'),'&quot;')

This expression selects the string between two quotes (&quot;= ") of the @value attribute.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Michael Kay
Solution 2 zx485