PHP getDocNamespaces() Function

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

public array SimpleXMLElement::getDocNamespaces ([ bool $recursive = FALSE [, bool $from_root = TRUE ]] )

Returns namespaces declared in document

Example -

Example #1 Get document namespaces

Example #2 Working with multiple namespaces

ParameterDescription
recursiveIf specified, returns all namespaces declared in parent and child nodes. Otherwise, returns only namespaces declared in root node.
from_rootAllows you to recursively check namespaces under a child node instead of from the root of the XML doc.

The getDocNamespaces method returns an array of namespace names with their associated URIs.