开发者

dom_import_simplexml() returns an empty object (PHP)

So, I want to ulti开发者_如何学Pythonmately create a DOM object for the XML, however, $xml_dom seems to be empty. var_dump shows object(DOMElement)#3 (0) { }. $xml_simple is good. What am I doing wrong here?

$get_url_report = 'http://...'; // contains well-formatted XML data
$xml_simple = simplexml_load_string(file_get_contents($get_url_report));
$xml_dom = dom_import_simplexml($xml_simple);


DOM doesn't work well with var_dump(), for example read this comment. Additional there is already a bug report (for over two years now ...).

The object is probably not empty, even if it looks so. You should be able to use it like described in the manual.


var_dump isn't useful for objects such as SimpleXMLElement or DOMElement. Try something like $xml_dom->tagName or $xml_simple->asXML() to see whether those objects have content.

P.S. you may also use simplexml_load_file($get_url_report) instead of simplexml_load_string(file_get_contents($get_url_report));

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜