Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 读取XML文件时出错_Php_Xml_Domdocument - Fatal编程技术网

Php 读取XML文件时出错

Php 读取XML文件时出错,php,xml,domdocument,Php,Xml,Domdocument,我正在使用以下代码 //定义要写入的文件名和要从中下载的url $filename = 'capital_one.xml'; $url = "http://feeds.perfb.com/index.php/download?OEMAIL=chirag_gir@visitwembley.co.uk&PX=e90daba5ee2c6fd4d0c344fd61911f33&DISPLAYFORMAT=HEAD&REVERSEMAPXML=yes&PRO

我正在使用以下代码

//定义要写入的文件名和要从中下载的url

    $filename = 'capital_one.xml';
    $url = "http://feeds.perfb.com/index.php/download?OEMAIL=chirag_gir@visitwembley.co.uk&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;


}
我犯了以下错误

可捕获的致命错误:传递给DOMNode::appendChild()的参数1必须是DOMNode的实例


您能帮助我吗?

如果
expand()
没有返回
DOMNode
,则会发生错误并返回
FALSE

您需要自己做一些调查,并告诉我们您发现了什么。错误发生在哪一行?通过搜索错误消息文本,您发现了什么?你读过模块的错误处理功能吗?我必须在代码中更改什么请帮助我建议在顶部添加
error\u reporting(-1)
ini\u set('display\u errors','on')
,以查看是否记录了任何错误。现在我得到了错误警告:XMLReader::read():/var/www/visitwembley.co.uk/development/capital_one.xml:86:解析器错误:xmlParseEntityRef:33行/var/www/visitwembley.co.uk/development/getxmldata.php中没有名字警告:XMLReader::read():第33行/var/www/visitwembley.co.uk/development/getxmldata.php中的旅行和假期警告:XMLReader::read():^in/var/www/visitwembley.co.uk/development/getxmldata.php第33行警告:XMLReader::read():在第33行读取/var/www/visitwembley.co.uk/development/getxmldata.php时出错,则您的XML格式不正确<代码>旅行和度假应为
旅行和度假;假期
我想是的。但是这个XML文件是在第三方生成的,所以我如何更改它?有没有其他代码可以改变这个?