PHP:DOM文档 - 在这一个冒号属性? [英] PHP: DOMDocument - attributes with a colon in it?
本文介绍了PHP:DOM文档 - 在这一个冒号属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的DOMDocument解析XML(SVG)。
I'm using DOMDocument to parse an XML (SVG).
某些节点会在其与结肠癌的属性,如:
Some nodes have attributes with a colon in it, like :
<svg
id="svg2"
width="1000"
height="1000"
sodipodi:version="0.32"
inkscape:version="0.48.1 "
...
>
但是,当我做的:
But when I do :
$node= DOMDocument->documentElement;
foreach($node->childNodes as $key=>$childnode) {
foreach($childnode->attributes as $attribute) {
echo $attribute->name."\n";
}
}
与属性的:打印不带的第一部分(命名空间)
the attributes with a : are printed without the first part (namespace)
我如何获得命名该属性通过这样的属性?
How do I get the namespace for that attribute when iterating through the attributes like this?
推荐答案
从OP的评论,节点名称
来自的的DOMNode 。
Answer from OP's comment, nodeName
from DOMNode.
$node= DOMDocument->documentElement;
foreach($node->childNodes as $key=>$childnode) {
foreach($childnode->attributes as $attribute) {
echo $attribute->nodeName."\n";
}
}
原来的答复:
如何 preFIX
来自的的DOMNode ?
$node= DOMDocument->documentElement;
foreach($node->childNodes as $key=>$childnode) {
foreach($childnode->attributes as $attribute) {
echo $attribute->prefix.":".$attribute->name."\n";
}
}
这篇关于PHP:DOM文档 - 在这一个冒号属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文