PHP getNamespace() 函數
定義和用法
getNamespace() 函數獲取在 XML 文檔中使用的命名空間。
如果成功,該函數返回命名空間(帶有關聯的 URL)的一個數組。如果失敗,則返回 false。
語法
class SimpleXMLElement { string getNamespace(recursive) }
參數 | 描述 |
---|---|
recursive | 可選。規定是否返回父子節點中使用的所有命名空間。默認是 false。 |
實例
XML 文件:
<?xml version="1.0" encoding="ISO-8859-1"?> <note xmlns:b="http://www.codew3c.com/example/"> <to>George</to> <from>John</from> <heading>Reminder</heading> <b:body>Don't forget the meeting!</b:body> </note>
PHP 代碼:
<?php if (file_exists('test.xml')) { $xml = simplexml_load_file('test.xml'); } print_r($xml->getNamespaces()); ?>
輸出類似:
Array ( [b] => http://www.codew3c.com/example/ )