note 47081 deleted from ref.dom by didou
| From: | didou@php.net | Date: | Sat, 02 Apr 2005 20:43:57 +0000 |
| Subject: | note 47081 deleted from ref.dom by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-87363@lists.php.net to get a copy of this message | ||
Note Submitter: franp at free dot fr
----
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.