PHP: DOMDocument - attributes with a colon in it?

∥☆過路亽.° 提交于 2019-11-29 16:34:31

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";
  }
}

Original Answer:

How about prefix from DOMNode?

$node= DOMDocument->documentElement;
foreach($node->childNodes as $key=>$childnode) {
  foreach($childnode->attributes as $attribute) {
    echo $attribute->prefix.":".$attribute->name."\n";
  }
}

You will need to work with namespaces (which is what the colon indicates) explicitly when you use DOMDocument.

Take a look at this method: http://www.php.net/manual/en/domelement.getattributenodens.php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!