importing node into document

Discussion in 'Python' started by Ajay, Aug 14, 2004.

  1. Ajay

    Ajay Guest

    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.
     
    Ajay, Aug 14, 2004
    #1
    1. Advertising

  2. Ajay

    Ivan Herman Guest

    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.
     
    Ivan Herman, Aug 15, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,617
  2. Ajay

    import node into document

    Ajay, Aug 15, 2004, in forum: Python
    Replies:
    0
    Views:
    313
  3. plb
    Replies:
    2
    Views:
    364
  4. Tjerk Wolterink
    Replies:
    2
    Views:
    1,477
    Dimitre Novatchev
    Aug 24, 2006
  5. Une Bévue

    importing an xml node into an xhtml one

    Une Bévue, Apr 12, 2008, in forum: Javascript
    Replies:
    4
    Views:
    95
    Une Bévue
    Apr 12, 2008
Loading...

Share This Page