Re: Using DOM textContent Property

From: Date: Tue, 09 Sep 2008 19:16:10 +0000
Subject: Re: Using DOM textContent Property
References: 1 2 3 4 5 6 7 8 9  Groups: php.general 
Request: Send a blank email to php-general+get-279747@lists.php.net to get a copy of this message
Nathan Nobbe wrote:
In my opinion, the DomNodeList class is useless.
agreed; ever tried making a replacement node class that extends it? then you see how useless it is! [yet a vital part of the dom structure] ot here; but I thought maybe useful for reference; I do loads of xml/dom api work and find that this little iterator is very very useful; I've trimmed it down but you'll find below how *I* iterate through the dom grabbing the important values.. private function iterateDom( $nodeList ) { foreach( $nodeList as $values ) {
    if( $values->nodeType == XML_ELEMENT_NODE ) {
      $nodeName = $values->nodeName;
      if( $values->attributes ) {
       for( $i=0;$values->attributes->item($i);$i++ ) {
        $attributeName = $values->attributes->item($i)->nodeName
        $attributeValue = $values->attributes->item($i)->nodeValue
       }	
      }
      $values->children = $this->iterateDom( $values->childNodes );
      $tempNode[$nodeName] = $values;
    } elseif( in_array($values->nodeType, array(XML_TEXT_NODE, XML_CDATA_SECTION_NODE)) ) {
      $nodeType = $values->nodeType;
      $nodeData = $values->data;
    } elseif( $values->nodeType === XML_PI_NODE ) {
      $DOMProcessingInstruction = array('target' => $values->target, 'data' => $values->data);
    }
# other wise we ignore as all that's left is DOMComment } } might be useful for somebody

« previous php.general (#279747) next »