我正在使用DOMDocument来解析
XML(SVG).
一些节点具有带冒号的属性,如:
<svg id="svg2" width="1000" height="1000" sodipodi:version="0.32" inkscape:version="0.48.1 " ... >
但当我这样做时:
$node= DOMDocument->documentElement; foreach($node->childNodes as $key=>$childnode) { foreach($childnode->attributes as $attribute) { echo $attribute->name."\n"; } }
带有:的属性是在没有第一部分(命名空间)的情况下打印的
从OP的评论中回答,nodeName来自
DOMNode.
原文链接:https://www.f2er.com/php/138570.html$node= DOMDocument->documentElement; foreach($node->childNodes as $key=>$childnode) { foreach($childnode->attributes as $attribute) { echo $attribute->nodeName."\n"; } }
原答案:
DOMNode的前缀怎么样?
$node= DOMDocument->documentElement; foreach($node->childNodes as $key=>$childnode) { foreach($childnode->attributes as $attribute) { echo $attribute->prefix.":".$attribute->name."\n"; } }