Re: DOMElement::setAttribute() manual example question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux