duanchi4544 2010-12-30 16:52
浏览 33
已采纳

自动将整个XML文档解析为PHP变量

Hey, Basically got a massive XML document, with lots of nodes n attributes values and all that jazz.

I'm wanting to be VERY lazy as I'm awful at XML/PHP and google seems to have failed me on this occasion.

if it possible to grab EVERY element in the XML document and make it a PHP variable?

So if my XML Doc was like maybe...

<wrap>
 <sub></sub>
  <subsub></subsub>
 <sub></sub>
  <subsub></subsub>
 <sub2></sub2>
 <sub3 value=''></sub3>
 <sub4 value=''></sub4>
</wrap>

so it would recursively check the document converting it all into php variables no matter what the name of the tags/nodes. so for example they would end up looking like maybe. $wrap; $sub1; $sub[2]; $sub2; $sub3; $sub4; $sub3['value']; $sub4['value'];

so it would have to me smart to delve deep into possibly like 8 children down?

is this possible or will i have to type out like $sub1 = $xml->wrap->sub1; because that's like...over 1k lines of code that i don't want to exist lol.

just incase the xml feed is HERE

thanks for your time :)

  • 写回答

3条回答 默认 最新

  • dongmouhao7438 2010-12-30 19:33
    关注
       $xml = simplexml_load_string($response);
    // $response is your xml file/output string
    

    you can then refer to elements within the $xml object like this

    $xml->children('yourschema')->children('yoururn')->Tag1->Tag2
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建