How how can I get a text from inside a node using xpath?
For now I'm doing it like this:
$temp= $content->xpath('qwe/qwe');
$temp = each($temp[0]);
return $temp['value'];
But as you can see it's far from good solution :(
In c# it is as easy as
public string readXmlVar(string xpath)
{
XmlNode xmlNode = xml.SelectSingleNode(xpath);
return xmlNode.InnerText;
}
For SimleXmlElement
just cast it as a string: return (string) $temp;
. For DomDocument
use 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.
(string) current($xml->xpath("//group[@ref='HS_TYP']"))
Hope that helps
This will get all inner text from simple xml element
dom_import_simplexml($xpath->query('//div[@class="h1"]')->textContent;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With