PHP getNamespaces()Function

PHP SimpleXML 参考手册PHP SimpleXML Reference Manual

Examples

Return the namespaces used in an XML document:

<?php
$xml=<<<XML
<?xml version="1.0" standalone="yes"?>
<cars xmlns:c="https://www.example.com/ns" xmlns:a="https://www.example.com/country">
<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->getNamespaces(true);
var_dump($ns);
?>

Run Example »

Definition and Usage

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


Syntax

getNamespaces(recursive);

Parameter Description
recursive Optional. Specifies a boolean value. If the value is TRUE, returns all namespaces declared in all parent and child nodes. If the value is FALSE, returns only the namespaces declared in the root node. Default is FALSE.

Technical Details

Return value: Returns an array of namespace names with associated URIs.
PHP Version: 5.1.2+


PHP SimpleXML 参考手册PHP SimpleXML Reference Manual Other Extensions