note 80985 added to ref.dom

From: Date: Sat, 09 Feb 2008 22:40:55 +0000
Subject: note 80985 added to ref.dom
Groups: php.notes 
Request: Send a blank email to php-notes+get-135939@lists.php.net to get a copy of this message
How to get contents of node with all tags by PHP Dom: <?php // XML data $xml_string = "<?xml version='1.0' ?> <sentence> How to get contents of node with all tags by PHP Dom: <br/> <b>cabbages</b>, <i>tomatoes</i>, <i>apples</i>, <font color='purple'>aubergines</font> <ol> <li> row 1</li> <li> row 2 </li> <li> row 3 </li> </ol> <table border = '1'> <tbody> <tr> <td>I am best</td> </tr> <tr> <td>Programmer</td> </tr> </tbody> </table> You see my projects at: <strong><a href='http://www.itdeveloping.eu' >www.itdeveloping.eu</a></strong> </sentence>"; // parse it $doc= new DOMDocument(); if (!$doc->loadXML($xml_string)) { echo ("Error in XML document"); } $nody = $doc->getElementsByTagName('sentence'); // gets NodeList $nod=$nody->item(0);//Node getContent($Content,$nod); echo $Content; function getContent(&$NodeContent="",$nod) { $NodList=$nod->childNodes; for( $j=0 ; $j < $NodList->length; $j++ ) { $nod2=$NodList->item($j);//Node j $nodemane=$nod2->nodeName; $nodevalue=$nod2->nodeValue; if($nod2->nodeType == XML_TEXT_NODE) $NodeContent .= $nodevalue; else { $NodeContent .= "<$nodemane "; $attAre=$nod2->attributes; foreach ($attAre as $value) $NodeContent .="{$value->nodeName}='{$value->nodeValue}'" ; $NodeContent .=">"; getContent($NodeContent,$nod2); $NodeContent .= "</$nodemane>"; } } } ?> ---- Server IP: 195.46.80.5 Probable Submitter: 195.91.54.86 ---- Manual Page -- http://www.php.net/manual/en/ref.dom.php Edit -- https://master.php.net/note/edit/80985 Del: integrated -- https://master.php.net/note/delete/80985/integrated Del: useless -- https://master.php.net/note/delete/80985/useless Del: bad code -- https://master.php.net/note/delete/80985/bad+code Del: spam -- https://master.php.net/note/delete/80985/spam Del: non-english -- https://master.php.net/note/delete/80985/non-english Del: in docs -- https://master.php.net/note/delete/80985/in+docs Del: other reasons-- https://master.php.net/note/delete/80985 Reject -- https://master.php.net/note/reject/80985 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#135939) next »