Get namespaces declared in parent and child nodes of the XML document in PHP
Description
The following code shows how to get namespaces declared in parent and child nodes of the XML document.
Example
// w w w . j av a2s .c o m
<?php
$xml=<<<XML
<cars xmlns:c="http://java2s.com/ns">
<c:car id="1">XML</c:car>
<c:car id="2">CSS</c:car>
<c:car id="3" a:country="Sweden" xmlns:a="http://java2s.com/country">Saab</c:car>
</cars>
XML;
$sxe=new SimpleXMLElement($xml);
$ns=$sxe->getDocNamespaces(TRUE);
var_dump($ns);
?>
The code above generates the following result.