note 44397 deleted from function.dom-domdocument-createelement by didou

From: Date: Sat, 30 Dec 2006 03:09:29 +0000
Subject: note 44397 deleted from function.dom-domdocument-createelement by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-121044@lists.php.net to get a copy of this message
Note Submitter: franp at free dot fr ---- AFAIK there is no way to return as a string a newly created node or element before attaching it to an existing DOMDocument. If you need to display a newly created node or element for debugging purposes - certainly you will at some point :-( , you must temporary append it to an existing DOMDocument. Example : <?php $newQuant = $caddy->createElement("quantity"); $newQuantText = $caddy->createTextNode("5"); $newQuant->appendChild($newQuantText); ?> // Until now no way to check the result // Let's append it to an existing DOMDocument : <?php $caddy->documentElement->appendChild($newQuant); ?> // Now we can display it as a string : <?php echo nl2br(htmlspecialchars( $caddy->saveXML($caddy->documentElement->lastChild))); ?> // This return : <?php <quantity>5</quantity> ?> // Do not forget to remove the appended node as it may : <?php $caddy->documentElement->removeChild($newQuant); ?> That's it ! It is a convenient workaround for the lack of "transformToXML" in php5.

« previous php.notes (#121044) next »