note 71576 deleted from ref.dom by didou

From: Date: Sat, 30 Dec 2006 03:03:12 +0000
Subject: note 71576 deleted from ref.dom by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-121038@lists.php.net to get a copy of this message
Note Submitter: aleczapka at gmx dot net ---- To recursivly walk trough HTML file one could do it like that (really simple function). <table> <tr> <td>1</td> <td>2</td> </tr> <tr> <td><p>3</p></td> <td><p>4</p></td> </tr> </table> <?php function nodeWalk(DomNodeList $node, $xpath="") { foreach ($node as $item) { if ($item->nodeType != 1) continue; $xpath .= "/".$item->tagName; echo $item->tagName . "<br />"; //do your stuff here $xpath = nodeWalk($item->childNodes, $xpath); } return $xpath; } $dom = new DomDocument(); $dom->load("xhtml.htm"); $table = $dom->getElementsByTagName("table"); $xPath = nodeWalk($table->item(0)->childNodes, "/".$table->item(0)->tagName); echo "xPath: ".$xPath; ?> It will output: tr td td tr td p td p xPath: /table/tr/td/td/tr/td/p/td/p

« previous php.notes (#121038) next »