I'm trying to read the relevant nodes in the following XML string, to finally display:
flerror:0
Message from directory:Pings being forwarded to 11 services!
<?xml version="1.0"?>
<methodResponse>
<params>
<param>
<value>
<struct>
<member><name>flerror</name><value><boolean>0</boolean></value></member>
<member><name>message</name><value><string>Pings being forwarded to 11 services!</string></value></member>
</struct>
</value>
</param>
</params>
</methodResponse>
I tried using:
$doc = new DOMDocument();
$doc->loadXML($xmlString);
$value = $doc->getElementsByTagName("value");
$value = $value->item(0)->nodeValue;
and obtained:
<br>flerror0<br>
messagePings being forwarded to 11 services!
I can then use string parsing functions to separate out the strings, but that I need a cleaner solution.
Any suggested improvements that will possibly avoid the additional string parsing?
Thanks!
nodeValuewill give you the combined DOMTextNode values of the element it is fetched for. If you want separate nodeValues, fetch separate nodes and format the output withsprintf