Who says that I have a well-formed DTD? DTD is not necessary in many
cases. I will illustrate with example why DOM is too "complex" ...
compared to SimpleXML.

<?php
//These are my 2 XML documents. No DTD - just a simple xml structure.
$xml1 = '<root1><q/><a><b><c><d>hi1</d></c></b></a><q/></root1>';
$xml2 = '<root2><q/><a><b><c><d>hi2</d></c></b></a><q/></root2>';

$sxe1 = new SimpleXMLElement ($xml1);
$sxe2 = new SimpleXMLElement ($xml2);

//Easy access to a node. It's great!
echo $sxe1->a->b->c->d;
echo $sxe2->a->b->c->d;

//But how can I understand what is the name of the root node?
$dom_sxe = dom_import_simplexml($sxe1);

//Hooray, we've got node name
echo $dom_sxe->nodeName;

//And what happens if element sequence changes? .
echo 
$dom_sxe->childNodes->item(1)->firstChild->firstChild->firstChild->nodeValue;
//... hm... I prefer SimpleXML.

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to