2011-07-19 55 views
1

所以,我想最終爲XML創建一個DOM對象,但是,$ xml_dom似乎是空的。 var_dump顯示對象(DOMElement)#3(0){}。 $ xml_simple很好。我在這裏做錯了什麼?dom_import_simplexml()返回一個空對象(PHP)

$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); 

回答

6

DOMvar_dump()很好地工作,例如讀取this comment。另外還有一個bug report(現在兩年多了......)。

該對象可能不是空的,即使它看起來如此。你應該能夠像手冊中描述的那樣使用它。

+0

你是對的。註釋鏈接中描述的行可用。儘管如此,如果沒有正確的縮進,很難閱讀。我現在可以堅持使用SimpleXML。 – musicliftsme

2

var_dump對於諸如SimpleXMLElement或DOMElement等對象沒有用處。嘗試類似$xml_dom->tagName$xml_simple->asXML()以查看這些對象是否具有內容。

P.S.你也可以用simplexml_load_file($get_url_report)代替simplexml_load_string(file_get_contents($get_url_report));