importing node into document

A

Ajay

hi!

is there an equivalent for the Java document.importNode in Python
what i am trying to do is to import a node from a different document into
the current document and then append it one of the nodes in the current
document
tempNode.ownerDocument = node.ownerDocument
#the above gives an error saying i am trying to modify a reda-only
attribute
#if i omit the statement, the statement below throws an error saying they
#the nodes are from different document
node.appendChild(tempNode)

thanks

cheers
 
I

Ivan Herman

In terms of XML two documents represent two different 'worlds'; a Node
also includes a reference to its own document, ie, you cannot easily
mix/merge etc, nodes in different namespaces. This reference is read
only. (As I already answered in one of your other messages, you should
really consider looking at the original DOM specification. That clearly
flags the 'ownderDocument' as 'readonly'!).

What you have to do is (recursively) create a new node in your target
document with the name of the original, then copy the attributes and
(recursively) the children.

Ivan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top