getDocNamespaces
返回文檔中聲明的命名空間。
getDocNamespaces()
函數返回XML 文檔中聲明的命名空間。
返回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); ?>
運行實例
返回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。 |