doufu6130 2014-05-22 15:06
浏览 64
已采纳

PHP simplexml_load_string不加载

I'm trying to use simplexml_load_string like so:

$xml = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <data_GetResult xmlns="http://api.source.com/">
      <data_GetData>
        <value>123456</value>
        <value>789000</value>
      </data_GetData>
    </data_GetResult>
  </soap:Body>
</soap:Envelope>';      

$results = simplexml_load_string($xml);
print_r($results);

However, no results are returned, it simply shows:

SimpleXMLElement Object
(
)

I believe the xml is proper, I tested it in on-line validators. Thank you.

  • 写回答

1条回答 默认 最新

  • dongmaobeng7145 2014-05-22 15:32
    关注

    Try this (as per the manual)

    <?php
    $string = <<<XML
    <?xml version="1.0" encoding="utf-8"?>
    <soap_Envelope xmlns_xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns_xsd="http://www.w3.org/2001/XMLSchema" xmlns_soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap_Body>
    <data_GetResult xmlns="http://api.source.com/">
    <data_GetData>
    <value>123456</value>
    <value>789000</value>
    </data_GetData>
    </data_GetResult>
    </soap_Body>
    </soap_Envelope>  
    XML;
    
    $xml = simplexml_load_string($string);
    
    print_r($xml);
    ?>
    

    It seems as though the : in your names were (which is odd they seem part of the scheme) causing the problem e.g.

    </soap:Body>
    </soap:Envelope>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 电脑出问题了,说是usbmom注册表没
  • ¥20 需要步骤截图(标签-服务器|关键词-map)
  • ¥50 gki vendor hook
  • ¥15 灰狼算法和蚁群算法如何结合
  • ¥15 这是一个利用ESP32自带按键和LED控制的录像代码,编译过程出现问题,请解决并且指出错误,指导如何处理 ,协助完成代码并上传代码
  • ¥20 stm32f103,hal库 hal_usart_receive函数接收不到数据。
  • ¥20 求结果和代码,sas利用OPTEX程序和D-efficiency生成正交集
  • ¥50 adb连接不到手机是怎么回事?
  • ¥20 抓取数据时发生错误: get_mooncake_data() missing 1 required positional argument: 'driver'的问题,怎么改出正确的爬虫代码?
  • ¥15 vs2022无法联网