![](/img/trans.png)
[英]Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' payleap
[英]PHP Uncaught exception 'Exception' with message 'String could not be parsed as XML
我对php函数SimpleXMLElement有问题。 这是我的代码:
echo $xmldata;
$nodes = new SimpleXMLElement($xmldata);
这段代码我的输出如下:
<?xml version="1.0" encoding="utf-8"?>
<node>
<node>
<title>CONTENT DI PROVA</title>
<body>CIAO CIAO
</body>
<created>Thursday, June 4, 2015 - 17:37</created>
<type>Article</type>
<field_geoposition>Geolocation is 45.4654219, 9.18592430000001</field_geoposition>
<path>/Argomentiamo/?q=node/1</path>
</node>
</node>
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in
/membri/****/*****/****:50 Stack trace: #0 /membri/****/*****/****(50): SimpleXMLElement->__construct('<code><span sty...') #1 /membri/****/*****/****(101): xmlToArel() #2 {main} thrown in /membri//****/*****/**** on line 50
但是如果我用SimpleXMLElement函数中的输出替换$ xmldata,如下所示:
echo $xmldata;
$nodes = new SimpleXMLElement( '<?xml version="1.0" encoding="utf-8"?>
<node>
<node>
<title>CONTENT DI PROVA</title>
<body>CIAO CIAO
</body>
<created>Thursday, June 4, 2015 - 17:37</created>
<type>Article</type>
<field_geoposition>Geolocation is 45.4654219, 9.18592430000001</field_geoposition>
<path>/Argomentiamo/?q=node/1</path>
</node>
</node>'/*$xmldata*/);
我没有错误...
编辑:也许问题是我使用highlight_string保留了我的xml:
$ch = curl_init($xmlsource);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$sorgente = curl_exec($ch);
curl_close($ch);
$xmldata = highlight_string($sorgente,true);
有人可以帮我吗?
我看到了您的错误消息的这一部分: SimpleXMLElement->__construct('<code><span sty...')
有了这个,我可以看到您的xml中有HTML代码,而且我想这是用于样式的。 从XML中删除它,它应该可以工作。
提示:调试时不要使用echo,而是使用var_dump进行输出。 您会看到的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.