note 44397 added to function.dom-domdocument-createelement
| From: | franp at free dot fr | Date: | Wed, 04 Aug 2004 18:02:16 +0000 |
| Subject: | note 44397 added to function.dom-domdocument-createelement | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-73942@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/function.dom-domdocument-createelement.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+44397
Delete -- http://master.php.net/manage/user-notes.php?action=delete+44397&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+44397&report=yes
Search -- http://master.php.net/manage/user-notes.php