简体   繁体   中英

how do I parse this in PHP

I am using simpleXML and get back the result like so:

SimpleXMLElement Object ( [@attributes] => Array ( [minorVersion] => 3 [majorVersion] => 3 [inferiorVersion] => 0 ) )

I would appreciate if I can get some help parsing this information - I have tried $xml(the oblect) like $xml->@attributes[minorVersion] but do not get anything back

Thanks

This is because the nodes are objects. One thing you can do is call the attributes() method which returns you an array. Make sure you always cast the result to an appropriate php type like (string), especially when doing comparisons.

$t = $xml->node->attributes();
echo (string) $t['minorVersion'];

You could also just try referencing it directly:

echo (string) $xml->node['minorVersion'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM