问题
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