Home > Software design >  In string which have escape characters, How to get element by useing Xpath?
In string which have escape characters, How to get element by useing Xpath?

Time:03-31

I have a html like this.

<div id="video1" value="&lt;iframe src=&quot;https://www.move.com/99&quot;&gt;&lt;/iframe&gt;"
></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.

CodePudding user response:

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.

CodePudding user response:

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.

  • Related