PHP: DOMDocument - attributes with a colon in it?

前端 未结 2 1930
粉色の甜心
粉色の甜心 2020-12-22 02:48

I\'m using DOMDocument to parse an XML (SVG).

Some nodes have attributes with a colon in it, like :



        
相关标签:
2条回答
  • 2020-12-22 03:17

    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

    0 讨论(0)
  • 2020-12-22 03:20

    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";
      }
    }
    
    0 讨论(0)
提交回复
热议问题