getDocNamespaces
Returns the namespace declared in the document.
getDocNamespaces()
function returns the namespace declared in the XML document.
Returns the namespace declared in the root node of the XML document:
<?php $xml = << < XML < ? xml version = "1.0" standalone = "yes" ?> < cars xmlns: c = " http://gitbox.net/ns " > < c: car id = " 1 " > Volvo </ c: car > < c: car id = " 2 " > BMW </ c: car > < c: car id = " 3 " > Saab </ c: car > </ cars > XML; $sxe=new SimpleXMLElement($xml); $ns=$sxe->getDocNamespaces(); print_r($ns); ?>
Run the instance
Returns all namespaces declared in the XML document:
<?php $xml = << < XML < ? xml version = "1.0" standalone = "yes" ?> < cars xmlns: c = " http://gitbox.net/ns " > < c: car id = " 1 " > Volvo </ c: car > < c: car id = " 2 " > BMW </ c: car > < c: car id = " 3 " a: country = " Sweden " xmlns: a = " http://gitbox.net/country " > Saab </ c: car > </ cars > XML; $sxe=new SimpleXMLElement($xml); $ns=$sxe->getDocNamespaces(TRUE); var_dump($ns); ?>
Run the instance
SimpleXMLElement :: getDocNamespaces ( recursive , from_root )
parameter | describe |
---|---|
Recursive |
Optional. Specifies a boolean value. If TRUE, return all namespaces declared in the document; If FALSE, only the namespace declared in the root node is returned. The default is FALSE. |
from_root |
Optional. Specifies a boolean value. TRUE Checks the namespace from the root node of the XML document; FALSE Check the namespace from the child node. The default is TRUE. |