Parsing XML with multiple namespaces

后端 未结 1 1509
遇见更好的自我
遇见更好的自我 2021-01-28 06:25

So I wanted to parse this XML:




        
相关标签:
1条回答
  • 2021-01-28 06:59

    The poorly documented fact in play here is that when you select a namespace with ->children, it remains in effect for descendent nodes.

    So when you ask for $sxe->children("soapenv", true)->Body->requestContactResponse, SimpleXML assumes you are still talking about the "soapenv" namespace, so is looking for the element <soapenv:requestContactResponse>, which doesn't exist.

    To switch back to the default namespace, you need to call ->children again, with a NULL namespace:

    $sx->children("soapenv", true)->Body->children(NULL)->requestContactResponse->requestContactReturn->id
    
    0 讨论(0)
提交回复
热议问题