how to use PHP to read XML, need help

Discussion in 'PHP' started by rcajht, Dec 16, 2007.

  1. #1
    I use following PHP code to read a XML file, but it only display word
    "string" on the page. what's wrong with these codes, do I need define subchild? and how to do that,
    a new PHP guy, need your help, thanks.

    PHP code:
    test XML file:

     
    rcajht, Dec 16, 2007 IP
  2. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $xml->children() will only get you the first "layer" of children. You need to insert further loops for each "sublayer", ie the node with its children or call the function recursively.
    Take a look at this example,
    http://www.php.net/manual/en/function.simplexml-element-children.php#75311
    and at the general description for simplexmlelement->children function, it's explained there, that you need a loop for each "generation" of children for specific node:
    http://www.php.net/manual/en/function.simplexml-element-children.php
     
    hogan_h, Dec 16, 2007 IP