【发布时间】:2012-10-16 18:12:40
【问题描述】:
我刚刚花了很长时间试图从 DOMNode 中删除一个带有命名空间的属性,但它根本不起作用。
xml 是从数据库生成的,如下所示:
<dictionary>
<row xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<table>answers</table>
<entity>Answer</entity>
</row>
<row xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<table>file_trans</table>
<entity>FileTrans</entity>
</row>
...
</dictionary>
我要删除的属性名称显然是“xmlns:xsi”。 postgres db 会自动添加它,我无法在那里删除它,所以我正在尝试使用 php 完成这项工作。
我将 xml 加载为 DOMDocument,然后对所有行元素执行一个 foreach 循环:
$xml = new DOMDocument();
$xml->loadXML($tablesInXml['xmlelement'], LIBXML_NOBLANKS);
foreach($xml->documentElement->childNodes as $row) {
$row->removeAttribute('xsi'); // not working
$row->removeAttribute('xmlns:xsi'); // not working
...
我什至尝试探查 DOMNode 属性,它根本不包含任何属性,并且显示长度为 0。
这是 php 5.3 中的错误吗?有人知道我还能做什么吗?
感谢您的任何回答
【问题讨论】: