duanchuan6350 2015-06-05 10:03
浏览 221

PHP未捕获异常'Exception',消息'String无法解析为XML

i have a problem with the php function SimpleXMLElement. This is my code:

 echo $xmldata;
 $nodes = new SimpleXMLElement($xmldata);  

Whit this code i have the output below:

 <?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

but if i replace the $xmldata with his output in the SimpleXMLElement function , like this:

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*/);

i have no error...

EDIT: maybe the problem is that i use highlight_string to keep my xml:

 $ch = curl_init($xmlsource); 
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
 $sorgente = curl_exec($ch); 
 curl_close($ch);
 $xmldata = highlight_string($sorgente,true); 

Someone can help me?

  • 写回答

1条回答 默认 最新

  • doumin4553 2015-06-05 10:10
    关注

    I see this part of your error message: SimpleXMLElement->__construct('<code><span sty...')

    With this I can see that you have HTML code in your xml, and I guess it's for styling. Remove that from the XML, and it should work.

    Tip: don't use echo, but var_dump for output while debugging. You would have seen this.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。