On Tuesday 01 November 2005 09:48, Marian Kostadinov wrote: > 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.
Well, If you are free to change the XML structure at any time - where's the point in wondering if an element is a parameter, a CDATA or an element? You can change everything to element and CDATA and that's all. If you have a fixed XML structure, that's not supposed to change, having a DTD is obligatory in orther to maintain consistency of the format. So, you can either work without using getType (since you define the XML structure yourself), or use a more complex API that will serve you well. > > <?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->nodeValu >e; //... hm... I prefer SimpleXML. -- Cyberly yours, Petar Nedyalkov Devoted Orbitel Fan :-) PGP ID: 7AE45436 PGP Public Key: http://bu.orbitel.bg/pgp/bu.asc PGP Fingerprint: 7923 8D52 B145 02E8 6F63 8BDA 2D3F 7C0B 7AE4 5436
pgpPy3wFRmlFk.pgp
Description: PGP signature