note 47081 added to ref.dom
| From: | franp at free dot fr | Date: | Tue, 02 Nov 2004 10:23:03 +0000 |
| Subject: | note 47081 added to ref.dom | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-79489@lists.php.net to get a copy of this message | ||
Since there is a complete interoperability between a DOM object and the corresponding SimpleXML
object, you may be tempted to interchange both in order to get the best of the two worlds to achieve
a given task.
If so, be aware that syntax of DOM and SimpleXML are, unfortunatly, not interoperable in most cases.
Consider for example the syntax to return a nodelist in both DOM and SimpleXML (in the following
example the root tag is supposed to be "<racine>"):
<?php
// DOM object method is "childNodes"
$doc = new DomDocument;
$doc->loadXML($str);
foreach ($doc->documentElement->childNodes as $child)
{ // do something }
// while SimpleXML method is "children()"
$sxml = simplexml_import_dom($doc);
foreach ($sxml->racine->children() as $child)
{ // do something }
?>
Nota : There is certainly some reason the php5 team chose to not unify DOM and SimpleXML and I am
not able, technicaly, to discuss that choice. It would just be nice if a comparative table of
syntaxes/methodes in DOM and SimpleXML was made available somewhere. Even if not comparative, simply
a table of all available methods in the DOM API and SimpleXML API would be of great help.
----
Manual Page -- http://www.php.net/manual/en/ref.dom.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47081
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47081&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47081&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47081&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47081&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47081&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47081&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47081&report=yes
Search -- http://master.php.net/manage/user-notes.php