[jdom-interest] Merging two Documents

tsasala at hifusion.com tsasala at hifusion.com
Thu Jul 20 05:22:13 PDT 2000


	What you are proposing is not straight forward at all.
If order doesn't matter, take all the element of one document
and add them to the other document.  Otherwise, you need to 
go through each element, find it, and add the children.
If the element is not in the document, add it under the
root. The basic outline is:

	doc2.root.getChildren.
	Iterate over children, looking for them in doc1.
	If child is in doc1
	  element = doc1.getElement(child.name)
	  element.addChildren(child.getChildren)
	else
	  doc1.root.addChild(child)


	This is not perfect, but it does most of the heavy
lifting.  (doc1 is your merged document)

	-Tom
	

Aleksi Kallio wrote:
> 
> Lets imagine we have two Documents:
> 
> First:
> <root>
>         <element>
>                 <fancy-element />
>         </element>
> </root>
> 
> Second:
> <root>
>         <element>
>                 <another-fancy-element />
>         </element>
>         <groovy-element />
> </root>
> 
> I want to merge them to create this Document:
> 
> <root>
>         <element>
>                 <fancy-element />
>                 <another-fancy-element />
>         </element>
>         <groovy-element />
> </root>
> 
> Is there an easy way to do this with JDOM? Will there be?
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com



More information about the jdom-interest mailing list