Parsing XML with multiple namespaces

后端 未结 1 1506
遇见更好的自我
遇见更好的自我 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 , 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)
提交回复
热议问题