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

时间:2016-07-17 21:20:52

标签: php html xml 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>

1 个答案:

答案 0 :(得分:-1)

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

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

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