简体   繁体   中英

Extracting data from XML using SimpleXML, 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 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> ?

好吧,这就是窍门:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM