【发布时间】:2013-04-09 16:08:43
【问题描述】:
我有一个文件 test.xml
<?xml version="1.0" encoding="UTF-8"?>
<item>
<dc:creator><![CDATA[hello world]]></dc:creator>
</item>
和代码 php
$doc = new DOMDocument();
$doc->load('test.xml');
$items = $doc->getElementsByTagName('item');
foreach ($items as $item) {
$authors = $item->getElementsByTagName( "dc:creator" );
$author = $authors->item(0)->nodeValue;
echo $author;
}
=> error can't get value, 如何得到这个,结果是“hello world”
【问题讨论】:
-
"dc" 这里是一个命名空间,它不被视为“标签名称”的一部分。试试
getElementsByTagNameNS。
标签: php xml domdocument xml-namespaces