importing node into document

Ivan Herman ivan at ivan-herman.net
Sun Aug 15 13:28:22 CEST 2004


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





Ajay wrote:

> 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
> 
> 
> 
> 
> 
> 
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.



More information about the Python-list mailing list