dongwei3120 2018-06-20 12:17
浏览 111

无法从XML加载字符串(SimpleXML)

I use PHP function simplexml_load_string and trying to get Data from XML Data But it look like i cannot get anything from this xml data

SimpleXMLElement Object ( [attribute] => Array ( [0] => SimpleXMLElement Object ( [name] => uname [value] => admin ) [1] => SimpleXMLElement Object ( [name] => playerlevel [value] => 1 ) [2] => SimpleXMLElement Object ( [name] => sessionid [value] => i9vfgvqo30c2kk2g57avmd0t ) ) )

This is my code

$xml = simplexml_load_string($request->body);

I have try with echo $xml[0], $xml[0]->value, $xml[1], It cannot get anything from this xml data.

  • 写回答

1条回答 默认 最新

  • duanhong4274 2018-06-21 08:13
    关注

    It's easier to derive the correct call from the XML rather than a print_r() from the SimpleXMLObject (which makes heavy use of Iterator and ArrayAccess)

    If the (reverse engineered) XML is something along

    <root>
        <attribute>
            <name>uname</name>
            <value>admin</value>
        </attribute>
        <attribute>
            <name>playerlevel</name>
            <value>1</value>
        </attribute>
        <attribute>
            <name>sessionid</name>
            <value>i9vfgvqo30c2kk2g57avmd0t</value>
        </attribute>
    </root>
    

    then the call sequence for the first <root><attribute><name> is

    $xml->attribute[0]->name
    
    评论

报告相同问题?

悬赏问题

  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题