Selecting Node with same names in XML with PHP - Confused
I have the following xml
<md f="a">
<![CDATA[ MR Adam Smith ]]>
</md>
<md f="b">
<![CDATA[ Smith, Adam ]]>
</md>
An开发者_C百科d I'm not sure how using PHP to echo the different md nodes using simplexml? So my current code below can only bring the first value of md node - but how do I get the other values of md? I looked at namespace- but these seems different.
$xml = simplexml_load_file($feedURL);
foreach($xml->results->result as $usern)
{
echo $usern->score . '<br>';
echo $usern->md. '<br>';
}
I've run into this problem before. You need to change how you create the SimpleXML object:
$xml = simplexml_load_file($feedURL, 'SimpleXMLElement', LIBXML_NOCDATA);
LIBXML_NOCDATA
will ensure you can grab the values from CDATA text.
This is mentioned in the comments (mario's in particular) of the simplexml_load_file()
documentation.
精彩评论