Re: Working with XML: DomDocument or SimpleXML?

From: Date: Fri, 21 Sep 2007 12:56:24 +0000
Subject: Re: Working with XML: DomDocument or SimpleXML?
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-262336@lists.php.net to get a copy of this message
Rob wrote: > Fairly unknown tidbit: you can pass SimpleXML objects to the XSL > extension. XSL will use the document from it. Nice to know... /me will have to experiment! >> if ($xml instanceof SimpleXMLElement) >> { >> $rv = new DOMDocument('1.0', 'utf-8'); >> $node = dom_import_simplexml($xml); >> $node = $rv->importNode($node, true); >> $rv->appendChild($node); >> return $rv; >> } > > Why??? If you really want a DOMDocument object why are you creating a > new document, copying nodes and incurring all the additional overhead? > > if ($xml instanceof SimpleXMLElement) > { > /* No copying, just use the existing XML tree directly */ > $node = dom_import_simplexml($xml); > return $node->ownerDocument; > } Yeah I had that initially too but that did not produce a DOMDocument Object but a DOMNode Object (or something like that.... will have to test again as memory is corrupted - there /was/ a reason, and stupid me didn't comment the code.....). Col

« previous php.general (#262336) next »