note 71576 added to ref.dom

From: Date: Wed, 06 Dec 2006 15:30:19 +0000
Subject: note 71576 added to ref.dom
Groups: php.notes 
Request: Send a blank email to php-notes+get-120341@lists.php.net to get a copy of this message
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 ---- Server IP: 195.136.184.34 Probable Submitter: 83.15.149.186 ---- Manual Page -- http://www.php.net/manual/en/ref.dom.php Edit -- https://master.php.net/note/edit/71576 Del: integrated -- https://master.php.net/note/delete/71576/integrated Del: useless -- https://master.php.net/note/delete/71576/useless Del: bad code -- https://master.php.net/note/delete/71576/bad+code Del: spam -- https://master.php.net/note/delete/71576/spam Del: non-english -- https://master.php.net/note/delete/71576/non-english Del: in docs -- https://master.php.net/note/delete/71576/in+docs Del: other reasons-- https://master.php.net/note/delete/71576 Reject -- https://master.php.net/note/reject/71576 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#120341) next »