2012-04-18 101 views
-1

我使用下面的代碼...錯誤在讀取XML文件

//定義我們想寫信給我們希望從

$filename = 'capital_one.xml'; 
    $url = "http://feeds.perfb.com/index.php/[email protected]&PX=e90daba5ee2c6fd4d0c344fd61911f33&DISPLAYFORMAT=HEAD&REVERSEMAPXML=yes&PRODUCTDB_ID=294"; 



//this creates the file "feed download".xml and takes he contents from the URL and stores them into the file 
file_put_contents($filename,file_get_contents($url)); 

//create instance of XMLReader 
    $xmlReader = new XMLReader(); 

//read in xml file 
$xmlReader->open($filename); 

//loop to read in data 
while($xmlReader->read()) 
{ 
     //this initialises the xml parser 
     $dom = new DOMDocument(); 
     $domNode = $xmlReader->expand(); 
     $element = $dom->appendChild($domNode); 
     $domString = utf8_encode($dom->saveXML($element)); 
     $product = new SimpleXMLElement($domString); 

     //read in data 
     echo $product_code = $product->product_code; 


} 

下載的文件名和URL我得到了以下錯誤

開捕致命錯誤:參數1傳遞給的DOMNode ::使用appendChild()必須的DOMNode

的實例

你能幫幫我嗎?

+1

你需要自己做一些調查,並告訴我們你的發現。錯誤發生在哪條線上?通過搜索錯誤消息文本找到了什麼?您是否閱讀過模塊的錯誤處理設施? – 2012-04-18 05:54:35

回答

1

如果expand()未返回DOMNode,則會發生錯誤,並返回FALSE

+0

我需要改變我的代碼請幫助 – banjali 2012-04-18 06:15:34

+0

我會建議在頂部添加'error_reporting(-1)'和'ini_set('display_errors','On')'以查看是否記錄了任何錯誤。 – 2012-04-18 06:29:36

+0

現在我得到錯誤警告:XMLReader :: read():/var/www/visitwembley.co.uk/development/capital_one.xml:86:解析器錯誤:xmlParseEntityRef:在/var/www/visitwembley.co中沒有名稱。第33行的uk/development/getxmldata.php警告:XMLReader :: read():Travel&Holidays in /var/www/visitwembley.co.uk/development/getxmldata.php on line 33警告:XMLReader :: read() :^在第33行的/var/www/visitwembley.co.uk/development/getxmldata.php中警告:XMLReader :: read():在/var/www/visitwembley.co.uk/development/中讀取時發生錯誤getxmldata.php 33行 – banjali 2012-04-18 06:34:46