Re: Using DOM textContent Property

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux