PHP getNamespaces() Function

Description

The getNamespaces() function returns the namespaces used in an XML document.

Syntax

PHP getNamespaces() Function has the following syntax.

getNamespaces(recursive);

Parameter

ParameterIs RequiredDescription
recursiveOptional.If TRUE, all namespaces declared in parent and child nodes are returned. If FALSE, only namespaces declared in root node is returned. Default is FALSE

Return

Returns an array of namespace names with their associated URIs

Example

Return the namespaces used in the XML document:


<?php/*www  .ja v a  2  s . c  o  m*/
$xml=<<<XML
<?xml version="1.0" standalone="yes"?>
<books xmlns:c="http://book.com/ns" xmlns:a="http://book.com/country">
  <c:book id="1">Java</c:book>
  <c:book id="2">PHP</c:book>
  <c:book id="3">CSS</c:book> 
</books>
XML;

$sxe=new SimpleXMLElement($xml);
$ns=$sxe->getNamespaces(true);
var_dump($ns);
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions