How get mixed content XML/HTM?

荒凉一梦 提交于 2019-12-14 03:12:16

问题


I have a mixed content like this:

    <root>
    <element1>
      text
    </element1>
      <element2>
        <text>A <i>b</i></text>
      </element2>
    </root>

I tried this Example to obtain the whole content with including the sub nodes with the tag "<i>", but in these two Examples I use Path to XML:

$reader->XML($xml); or 
$dom->loadXML($xml); $xpath = new DOMXpath($dom);  

and obtaining whole content of the XML. How can I obtain just the result text "A b"?


回答1:


Should be used:

$nodes = $xpath->evaluate(
 '//*|//text()[normalize-space(.) != ""]'
);

Absolute pathway to the source.



来源:https://stackoverflow.com/questions/54852697/how-get-mixed-content-xml-htm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!