Extracting data from XML using SimpleXML, third-level

孤街浪徒 提交于 2019-12-25 04:45:30

问题


I'm trying to extract data from an xml file. The problem is I know how to do the second level, but not a third level.

Here's a sample test of the XML

<createacct>
  <result>
    <options>
     <ns></ns>
    </options>
    <rawout>
    stuff
    </rawout>
    <status>1</status>
    <statusmsg>success</statusmsg>
  </result>
</createacct>

Now, how would I extract the data from: <rawout>, <status> and <statusmsg>? I may need to look at <result><options><ns> as well.

I suppose maybe:

$yop = new SimpleXMLElement ($xmlFile);
$rawout = array((string) $yop->rawout); // for rawout

and so forth for <status> and <statusmsg>. But what for <result><options><ns>?


回答1:


Well, this does the trick:

$xml->result[0]->options->ns


来源:https://stackoverflow.com/questions/4484516/extracting-data-from-xml-using-simplexml-third-level

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!