Return the namespaces used in the XML document in PHP

Description

The following code shows how to return the namespaces used in the XML document.

Example


  /*  ww  w  .  j a v a2 s  . c o  m*/
<?php
   $xml=<<<XML
   <cars xmlns:c="http://java2s.com/ns" xmlns:a="http://java2s.com/country">
     <c:car id="1">XML</c:car>
     <c:car id="2">CSS</c:car>
     <c:car id="3">HTML</c:car> 
   </cars>
XML;
   
   $sxe=new SimpleXMLElement($xml);
   $ns=$sxe->getNamespaces(true);
   var_dump($ns);
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    XML »




DOM
SimpleXML
SimpleXMLElement
XML Parser