Get the namespaces declared in the root of the XML document: in PHP
Description
The following code shows how to get the namespaces declared in the root of the XML document:.
Example
//w ww.j av a 2 s. co 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">Saab</c:car>
</cars>
XML;
$sxe=new SimpleXMLElement($xml);
$ns=$sxe->getDocNamespaces();
print_r($ns);
?>
The code above generates the following result.