There's something I don't fully understand about node cloning with the PHP's DOM api. Here's a sample file that quickly duplicates the issue I'm coming across.
$doc = new DOMDocument( '1.0', 'UTF-8' );
$root = $doc->createElement( 'root' ); // This doesn't work either $root = new DOMElement( 'root' );
$doc->appendChild( $root );
$doc2 = new DOMDocument( '1.0', 'UTF-8' );
$root2 = $doc2->createElement( 'root2' );
$doc2->appendChild( $root2 );
// Here comes the error
$root2->appendChild( $root->cloneNode() );
When you run this little snippet an exception is thrown
Fatal error: Uncaught exception
'DOMException' with message 'Wrong
Document Error'
Can I not grab a node from a document, clone it, and then append it to another document?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…