But as it has been outlined, when you ignore the namespace you'll also loose important information. For example with the document you have you're actually interested in the attendee and common elements, the service elements deal with the transport:$uriAtt = 'http://www.webex.com/schemas/2002/06/service/attendee';$xml->registerXPathNamespace('att', $uriAtt);$uriCom = 'http://www.webex.com/schemas/2002/06/common';$xml->registerXPathNamespace('com', $uriCom);$result = $xml->xpath('//att:*|//com:*');foreach ($result as $element) { $depth = count($element->xpath("./ancestor::*[namespace-uri(.) = '$uriAtt' or namespace-uri(.) = '$uriCom']")); $indent = str_repeat(' ', $depth); printf("%s %s\n", $indent, $element->getName());}这次的示例输出: attendee person name firstName lastName address addressType phones email type contactID joinStatus meetingKey那么为什么要删除所有名称空间?它们可以帮助您获取您感兴趣的元素.您也可以动态地进行So why drop all the namespaces? They help you to obtain the elements you're interested in. You can also do it dynamically 这篇关于具有许多名称空间的PHP解析XML响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-02 13:22