Re: [PHP] Re: SimpleXML & libxml options (XInclude)
- From: rrichards@xxxxxxxxxxxxxxxx (Rob Richards)
- Date: Wed, 28 Feb 2007 16:02:43 -0500
Ben Roberts wrote:
So really when you perform:Not exactly, but the idea is along those lines.
$dom = dom_import_simplexml($xml);
the $dom object is really created by taking a reference to the $xml object rather than copying it? i.e. (I know this isn't real code)
$dom = dom_import_simplexml(& $xml);
What is happening is that $dom (DOMElement in this case) now points to the same libxml2 structure as does $xml (SimpleXMLElement).
So now when you modify the structure of the document with one, it is reflected by the other because they are in the same document. This also means that it is possible that objects can become invalid by changes made in the other extension.
$sxe = new SimpleXMLElement("<root><child><inner>text</inner></child></root>");
$sxechild = $sxe->child->inner[0];
$dom = dom_import_simplexml($sxe);
$dom->removeChild($dom->firstChild);
var_dump($sxechild);
PHP Warning: var_dump(): Node no longer exists in /home/rrichards/temp.php on line 8
object(SimpleXMLElement)#3 (0) {
}
This shows that $sxechild is still an SimpleXMLElement, but warnings are issues that the node it refers to in the document no longer exists.
Although I doubt someone use the code above, it is the smallest piece of code I could write to demonstrate the possibility.
Rob
.
- Follow-Ups:
- Re: [PHP] Re: SimpleXML & libxml options (XInclude)
- From: Ben Roberts
- Re: [PHP] Re: SimpleXML & libxml options (XInclude)
- References:
- SimpleXML & libxml options (XInclude)
- From: Ben Roberts
- Re: SimpleXML & libxml options (XInclude)
- From: Rob
- Re: [PHP] Re: SimpleXML & libxml options (XInclude)
- From: Ben Roberts
- Re: [PHP] Re: SimpleXML & libxml options (XInclude)
- From: Rob Richards
- Re: [PHP] Re: SimpleXML & libxml options (XInclude)
- From: Ben Roberts
- SimpleXML & libxml options (XInclude)
- Prev by Date: Re: [PHP] Re: SimpleXML & libxml options (XInclude)
- Next by Date: Re: [PHP] Re: how to display images stored in DB
- Previous by thread: Re: [PHP] Re: SimpleXML & libxml options (XInclude)
- Next by thread: Re: [PHP] Re: SimpleXML & libxml options (XInclude)
- Index(es):
Relevant Pages
|