Parsing XML with PHP's simpleXML

前端 未结 5 1451
北恋
北恋 2020-12-11 10:23

I\'m learning how to parse XML with PHP\'s simple XML. My code is:



        
5条回答
  •  攒了一身酷
    2020-12-11 10:52

    For the part about the default namespace, read fireeyedboy's answer. As mentionned, you need to register a namespace if you want to use XPath on nodes that are in the default namespace.

    However, if you don't use xpath(), SimpleXML has its own magic that selects the default namespace automagically.

    $xmlSource = "         myApp  ";
    
    $Document = new SimpleXMLElement($xmlSource);
    
    foreach ($Document->iTunes as $iTunes)
    {
        echo $iTunes, PHP_EOL;
    }
    

提交回复
热议问题