PHP getNamespaces() Function

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

public array SimpleXMLElement::getNamespaces ([ bool $recursive = FALSE ] )

Returns namespaces used in document

Example -

The above example will output:

array(1) {
  ["p"]=>
  string(21) "http://example.org/ns"
}

ParameterDescription
recursiveIf specified, returns all namespaces used in parent and child nodes. Otherwise, returns only namespaces used in root node.

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