开发者

Selecting Node with same names in XML with PHP - Confused

开发者 https://www.devze.com 2023-04-02 04:21 出处:网络
I have the following xml <md f=\"a\"> <![CDATA[ MR Adam Smith ]]> </md> <md f=\"b\">

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消