开发者

Extracting data from XML using SimpleXML, third-level

开发者 https://www.devze.com 2023-01-31 21:16 出处:网络
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.

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 d开发者_如何学Goata 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>?


Well, this does the trick:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号