Hi Rob!

Rob wrote:

<?php
$doc = new DOMDocument("1.0");
$node = $doc->createElement("root");
$node->setAttribute("align", "left");
$doc->appendChild($node);
echo $doc->saveXML();
?>

Both ways are perfectly valid. $node and $newnode refer to the same object. It was written the 1st way to demonstrate the return value of appendChild(), because in many cases people create the element differently.

i.e.

$newnode = $doc->appendChild($doc->createElement("root"));
or
$newnode = $doc->appendChild(new DOMElement("root"));

Thank you very much for confirming that! I was not sure if it's really the same.

Also, in the event $node is created using the new DOMElement syntax:

$node = new DOMElement("root");

the node is read only and must be appended into the tree before it can be modified, so the example just tries to be neutral here regarding the syntax used.

$node = new DOMElement("root");

is read only, while

$node = $doc->createElement("root");

is not? Why?


btw., I think this: http://news.php.net/php.internals/22117 is a very, very, very good idea! I hope the patch will make it into core soon!


best regards
Andreas

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to