当前位置: 首页> 函数类别大全> getDocNamespaces

getDocNamespaces

返回文档中声明的命名空间。
名称:getDocNamespaces
分类:未分类
所属语言:php
一句话介绍:返回文档中声明的命名空间。

定义和用法

getDocNamespaces() 函数返回 XML 文档中声明的命名空间。

实例

例子 1

返回 XML 文档根节点中声明的命名空间:

<?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);
?>

运行实例

例子 2

返回 XML 文档中声明的所有命名空间:

<?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);
?>

运行实例

语法

SimpleXMLElement::getDocNamespaces(recursive, from_root)
参数 描述
recursive

可选。指定布尔值。

如果为 TRUE,则返回文档中声明的所有命名空间;

如果为 FALSE,则仅返回根节点中声明的命名空间。

默认为 FALSE。

from_root

可选。指定布尔值。

TRUE 从 XML 文档的根节点检查命名空间;

FALSE 从子节点检查命名空间。

默认为 TRUE。

同类函数