Mantis Bugtracker
  

Viewing Issue Advanced Details Jump to Notes ] View Simple ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0003064 [Quercus] major always 11-11-08 04:17 11-11-08 04:17
Reporter alexbu View Status public  
Assigned To
Priority normal Resolution open Platform
Status new   OS
Projection none   OS Version
ETA none Fixed in Version Product Version 3.2.1
  Product Build
Summary 0003064: DOMNamedNodeMap cannot be used in foreach statement
Description It's not possible to use 'foreach' statement to iterate over an instance of DOMNamedNodeMap, returnted by $domElement->attributes, where $domElement is DOMElement

Though, there is no problem with iterating over DOMNodeList, returned by $domElement->childNodes
Steps To Reproduce
Additional Information <?php

$test_str = "<?xml version='1.0' encoding='utf-8'?>
<root>
    <first attr1='value1' attrx='attrx'/>
    <second attr2='value2'/>
    <third/>
</root>";

function node_value($node) {

    foreach ($node->childNodes as $item) {
        if ($item instanceof DOMText)
            continue;
        
        echo 'node: ' . $item->nodeName . "\n";
        
        if ($item->hasAttributes()) {
            foreach($item->attributes as $attr) {
                echo 'attribute: ' . $attr->nodeName . ' with value: ' . $attr->nodeValue . "\n";
            }
        }
        
        if ($item->hasChildNodes())
            node_value($item);
    }
    
}

$doc=new DOMDocument();
if($doc->loadXML($test_str)===false)
    return false;

echo 'root:' . $doc->documentElement->nodeName . "\n";

node_value($doc->documentElement);
Attached Files

- Relationships

There are no notes attached to this issue.

- Issue History
Date Modified Username Field Change
11-11-08 04:17 alexbu New Issue
11-11-08 04:18 alexbu Issue Monitored: alexbu


Mantis 1.0.0rc3[^]
Copyright © 2000 - 2005 Mantis Group
27 total queries executed.
24 unique queries executed.
Powered by Mantis Bugtracker