PHP SimpleXML issue

泪湿孤枕 提交于 2019-12-11 08:55:51

问题


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?


回答1:


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/



来源:https://stackoverflow.com/questions/5899747/php-simplexml-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!