PHP getNamespace() 函数


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.w3school.com.cn/example/"><to>George</to><from>John</from><heading>Reminder</heading><b:body>Don't forget the meeting!</b:body></note>

PHP 代码:

<?phpif (file_exists('test.xml'))  {  $xml = simplexml_load_file('test.xml');  }print_r($xml->getNamespaces());?>

输出类似:

Array([b] => http://www.w3school.com.cn/example/)
标签:, , ,