XML with varying amount of child nodes for each parent node

后端 未结 1 1958
失恋的感觉
失恋的感觉 2021-01-23 09:31

So I have XML in the following format which I am reading from file \'test.xml\'



    
                 


        
相关标签:
1条回答
  • 2021-01-23 09:42

    Look at this:

    $sxe = new SimpleXMLElement($xmlstr);
    
    echo 'Agent | Code | Name'.PHP_EOL;
    foreach ( $sxe->Agent as $agent )
    {
        $attr = $agent->attributes();
    
        foreach ( $agent->Property as $property )
        {
            echo $attr['ID'].' | '.$property->Code.' | '.$property->Name.PHP_EOL;       
        }
    }
    
    0 讨论(0)
提交回复
热议问题