Valores devueltos

User Contributed Notes 5 notes

Remeber that DOMNode always needs a reference to a parent node or DOMDocument.

For example, if you try to clone a node - copy all children - and overwrite or delete the variable which holds the cloned node - all children will loose any reference and getting invalid.

This will cause a nice message like "Couldn't... node no longer exists" if you have luck. In most cases PHP only gives you the poor information "Couldn't fetch DOM[...]" which makes hard to find out whats going on, depending on the current operation.

/* cloneNode(false) does not omit Attributes of cloned node, to achieve this an iteration is required. this is probably less efficient than merely creating a new node from the desired nodeName but in some cases could be useful.

use case:

omit subnodes and attributes of secured portions of an xml document without altering expected general structure;*///xml to use

If you have an object that holds a DOMNode, cloning the object won't clone the DOMNode with it. If you simply copy the object or add its DOMNode several times, you will in fact only move the DOMNode in the tree, not multiply it. That might seem obvious, but took me half a day to find out.