Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP getDocNamespaces() Function

PHP getDocNamespaces() Function

PHP SimpleXML Reference Manual PHP SimpleXML Reference Manual

Example

Return the namespaces declared in the root node of an XML document:

Volvo

BMW

Saab

XML;

$sxe=new SimpleXMLElement($xml);

$ns=$sxe->getDocNamespaces();

print_r($ns);

?>

Run Example »


Definition and Usage

The getDocNamespaces() function returns the namespaces declared in an XML document.


Syntax

getDocNamespaces(

recursive

,

from_root

);

Parameters Description
recursive Optional. Specifies a boolean. If TRUE, returns all namespaces declared in all parent and child nodes. If FALSE, only returns the namespaces declared in the root node. Default is FALSE.
from_root Optional. Specifies a boolean. If TRUE, checks the namespace in the root node of the XML document. If FALSE, checks the namespace under child nodes. Default is TRUE.

Technical Details

Return Value: Returns an array of namespace names with their associated URIs.
PHP Version: 5.1.2+
PHP Changelog: PHP 5.4: Added from_root parameter was added.

More examples

Example 1

Return all namespaces declared in the parent and child nodes of an XML document:

Volvo

BMW

Saab

XML;

$sxe=new SimpleXMLElement($xml);

$ns=$sxe->getDocNamespaces(TRUE);

var_dump($ns);

?>

Run Example »


PHP SimpleXML Reference Manual PHP SimpleXML Reference Manual