You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Malcolm Robbins <mr...@paradise.net.nz> on 2002/04/28 13:07:33 UTC

How do I easily clone most of a document

Hi,

I'm having trouble (in the form of DOM005 and DOM006 errors) trying to pretty well clone most of a document.  In particular if I have a document like this (ignoring the processsing instructions, DOCTYPE etc):

<root_element>
        <header>
            <action>ADD</action>
            ... (a defined hierarchy)
        </header>
        <body>
            .. (a defined hierarchy)
        </body>
</root_element>
        
and I want to duplicate all the elements within the same document, changing the <action> value to say CHANGE for the second set, as follows:

<root_element>
        <header>
            <action>ADD</action>
            ... (a defined hierarchy)
        </header>
        <body>
            .. (a defined hierarchy)
        </body>

        <header>
            <action>CHANGE</action>
            ... (a defined hierarchy)
        </header>
        <body>
            .. (a defined hierarchy)
        </body>
</root_element>
        
How can I do this?  I've tried various combinations of cloneNode etc but always get either DOM005 Wrong document, DOM006 Hierarchy request error or some other error.

By the way I'd like to know how to do this with DOM 1 and DOM 2.

Any help much appreciated.

--malcolm