If deep is false, the node's attributes aren't imported (using PHP 5.0.4). You can use the following if you want to import attributes but not child nodes:
$document->importNode ($node->cloneNode (false), true);
DOMDocument->importNode()(no version information, might be only in CVS) DOMDocument->importNode() -- Import node into current document说明class DOMDocument {DOMNode importNode ( DOMNode importedNode [, bool deep] ) } This function returns a copy of the node to import and associates it with the current document. 参数
add a note
User Contributed Notes
benno at transmog dot nospam dot com dot au
23-Oct-2006 03:04
If deep is false, the node's attributes aren't imported (using PHP 5.0.4). You can use the following if you want to import attributes but not child nodes:
adjwilli
06-Oct-2006 04:08
Editing XML with PHP can be a pain in the Secretary of State Powell, so here's a script to replace an XML node with a user-provided one through the POST. It's usually a good idea to run the $_POST['xml'] through a validation check and clean it for other thing before running this.
stomas
19-Sep-2006 09:14
I think this should do the same:
Colin
13-Sep-2006 12:11
As of PHP 5.1.6 with libxml 2.6.26 and DOM/XML API version 20031129, importNode() does nothing if attempting to import from the same document. Meaning, if you do an $ret = importNode and then appendChild($ret) or insertBefore($ret, ...) then you will end up *moving* the node instead of ending up with a copy.
andy dot clark at dial dot pipex dot com
16-Aug-2006 09:10
Please ignore the previous comment, it's incorrect. Fitopaldi's example of 3rd Aug 2005 is all you need to copy a node and it's sub nodes. This is what the "deep" flag is doing.
andy dot clark at dial dot pipex dot com
15-Aug-2006 11:20
One useful use of importNode is to copy one node onto another.
TJ <php at tjworld dot net>
04-Nov-2005 05:15
Beware if you're working with classes you've extended from DOMNode, DOMElement, etc.
Fitopaldi
04-Aug-2005 02:29
importNode returns a copy of the node to import and associates it with the current document, but not import the node to the current DOMDocument. Use appendChild for import the copy of the node to current DOMDocument. | ||