简体   繁体   中英

PHP SimpleXML issue

I'm trying to get an xml stream by using curl. I've recieved the string with curl but I'm having troubles parsing the xmlstream with SimpleXML. The url im using is http://www.google.com/books/feeds/volumes/fR4vqfywNlgC and it seems to be ignoring the parts containing "dc". Why?

The dublin core data (at least, I'm assuming that's what the DC prefix means in this case) uses its own namespace. You need to refer to that namespace when retrieving these elements. This can be done using the ' children ' method.

Example:

$sxml = simplexml_load_string($xml);
$dcData = $sxml->children('dc', TRUE);
echo (string)$dcData->creator;

An article/posting detailing the problem and solution can be found here.

http://blogs.sitepoint.com/simplexml-and-namespaces/

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