我是否可以使用 XPath 在 XML 节点中提取(转义的)HTML 属性


Can I extract a (escaped) HTML attribute within an XML node using XPath?

如您所见,XML节点"description"包含转义的HTML,我需要提取第一个img的src属性。 有没有办法用XPath做到这一点?

<item>
    <description>&lt;img  class=&quot;imagefield imagefield-field_teaser_astory&quot; width=&quot;481&quot; height=&quot;455&quot; alt=&quot;&quot; src=&quot;http://www.rightwingwatch.org/sites/default/files/images/a_story_rww/roundup_A_.jpg?1383082488&quot; /&gt; Is Trump Going To Run The Country The Way He&amp;rsquo;s Running This Convention?</description>
</item>

您可以使用基本的子字符串函数:

substring-before(substring-after(/item/description/text(), 'src="'), '"')

这将按文档顺序在第一个/item/description文本节点中查找 src="" 之间的所有文本。