Java calls for XML adding.

Has anyone used the 'importNode' and the 'replaceChild' methods

of Interface Document and Node or adding 2 XML documents ?

I need to add 2 XML documents in Java.

DocumentOne

--

<?xml version="1.0" encoding="UTF-8"?>

<i:Interest xmlns:i="http://www.ABC.com/interests:i">

<i:ID>0</i:ID><i:Generation/>

<i:Delta/><i:Ref/>

</i:Interest>

DocumentTwo

--

<i:Underlying xmlns:i="common" xmlns:common="http://www.ABC.com/common" value="KGF">

<common:Code>KGF</common:Code>

<common:Class>STOCK</common:Class>

</i:Underlying>

Output Format

-

<?xml version="1.0" encoding="UTF-8"?>

<i:Interest xmlns:i="http://www.ABC.com/interests:i">

<i:ID>0</i:ID><i:Generation/>

<i:Delta/><i:Ref/>

<i:Underlying xmlns:i="common" xmlns:common="http://www.ABC.com/common" value="KGF">

<common:Code>KGF</common:Code>

<common:Class>STOCK</common:Class>

</i:Underlying>

</i:Interest>

My Java code is trying to use this

DocumentOne.importNode(DocumentTwo,true)

DocumentOne.replaceChild...

Please,has anyone used the above methods?

How can I add both the XML docs?

Help really appreciated

[1778 byte] By [bhuru_luthriaa] at [2007-11-27 3:05:18]
# 1
Please has anyone appended 2 XML files using importNode and replaceChild?
bhuru_luthriaa at 2007-7-12 3:50:42 > top of Java-index,Java Essentials,Java Programming...
# 2
please can anyone answer.?Help appreciated
bhuru_luthriaa at 2007-7-12 3:50:42 > top of Java-index,Java Essentials,Java Programming...
# 3
If my memory serves me right, with the normal API you can only manipulate nodes of the same document, that is, you can only insert Nodes into the same document where they come from. Maybe JDOM is more lenient from this point of view.
BIJ001a at 2007-7-12 3:50:42 > top of Java-index,Java Essentials,Java Programming...
# 4

Hi,Thanks for the reply.

Java 1.5 Document.importNode API states that:

Imports a node from another document to this document, without altering or removing the source node from the original document; this method creates a new copy of the source node. The returned node has no parent; (parentNode is null).

I need to add these 2 XML documents.

bhuru_luthriaa at 2007-7-12 3:50:42 > top of Java-index,Java Essentials,Java Programming...
# 5
So what about giving it a try?
BIJ001a at 2007-7-12 3:50:42 > top of Java-index,Java Essentials,Java Programming...
# 6

tried.

giving an error when I use importNode

nsoXMLDoc.importNode(commonCodeDocument, true);

Exception in thread "pool-1-thread-1" org.w3c.dom.DOMException: NOT_SUPPORTED_ERR: The implementation does not support the requested type of object or operation.

at org.apache.xerces.dom.CoreDocumentImpl.importNode(Unknown Source)

Thats why I am trying to contacy you chaps to see whether anyone has used this

bhuru_luthriaa at 2007-7-12 3:50:42 > top of Java-index,Java Essentials,Java Programming...
# 7
No problems.Thanks for your help anyway
bhuru_luthriaa at 2007-7-12 3:50:42 > top of Java-index,Java Essentials,Java Programming...
# 8

JDOM's org.jdom.Content has this:

public java.lang.Object clone()

/*

Returns a deep, unattached copy of this child and its descendants detached from any parent or document.

Overrides:

clone in class java.lang.Object

Returns:

a detached deep copy of this child and descendants

*/

BIJ001a at 2007-7-12 3:50:42 > top of Java-index,Java Essentials,Java Programming...
# 9
say we have two documents doc1 and doc1 and an node N1 of doc1 is to be added to Node N2 of doc2 then the following code works.Node imp = doc2.importNode(N1, true);N2.insertBefore(imp, N2.getNextSibling());Thanks for you previous comments... That helped a bit...
harunprasada at 2007-7-12 3:50:42 > top of Java-index,Java Essentials,Java Programming...