[ACCEPTED]-Php and Xpath - how to get text from inside a node-xpath
Accepted answer
For SimleXmlElement
just cast it as a string: return (string) $temp;
. For DomDocument
use 1 return $temp->nodeValue
.
Try:
$dom = new DOMDocument;
$dom->loadXML('<root>
<p>some text<br />some more text</p>
</root>');
$xpath = new DOMXPath($dom);
foreach ($xpath->query('/root/p/text()') as $textNode) {
echo $textNode->nodeValue;
}
$textNode
will be a DOMText.
0
(string) current($xml->xpath("//group[@ref='HS_TYP']"))
Hope that helps
0
This will get all inner text from simple 1 xml element
dom_import_simplexml($xpath->query('//div[@class="h1"]')->textContent;
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.