Current Location: Home> Function Categories> getDocNamespaces

getDocNamespaces

Returns the namespace declared in the document.
Name:getDocNamespaces
Category:Uncategorized
Programming Language:php
One-line Description:Returns the namespace declared in the document.

Definition and usage

getDocNamespaces() function returns the namespace declared in the XML document.

Example

Example 1

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

Example 2

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

grammar

 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.

Similar Functions
Popular Articles