Merging 2 documents DOM4J please help I'm getting lost

User 35bef27df0

02-05-2006 18:00:47

DOm4J can not merge 2 documents





setContent works but clears ALL previous contend





element.appendContent(Branch) has No result ???


are ther other rules to respect


ex





<root><info a="original/></root>





append <info b="append" />








Element(Root/info) .asXML shows <info a="original/>


Element(Root/info).appendContent(branch(<info b='appen' />


just does not do anithing no errors no insert











static public void appenLIST(Branch nod,List branch,int counts)


{ int count=0;


if (!(Nod instanceof Element)) Nod=Nod.getParent();//force element


Element Parent=nod.getParent();


if (Parent!=null)Parent.remove(nod);//works


if (counts==0) //only for the first


while (count < br.size())


{ Branch lstitm=(Branch) branch.get(count);


// ((Element)nod).add(lstitm.detach()) ;//FAILS ONLY node NOT THE CONTENT IS COPIED


((Element) nod).appendContent(lstitm) ; //no result !!!????


System.out.print("\n"+((Element) Parent).getDocument().asXML());


count++;}


}

ChemAxon a3d59b832c

03-05-2006 05:45:34

Hi,





In this forum, we can only help in questions related to ChemAxon products. I suggest to approach the dom4j user list with your question:





http://www.mail-archive.com/dom4j-user%40lists.sourceforge.net/





Best regards,


Szabolcs

18-06-2007 02:20:26

Is it really necessary to do it at the XML parsing level? There is a


requirement that an XML document contain just a single element at the top


level, so it is impossible to create a well-formed document that is the


composite of two other well-formed documents, unless you wrap the whole


thing


in a dummy element. I don't think this is really what you want.





If all you want to do is use 2 source documents in your transformation, use


XSLT's document function. For example, to get the union of root nodes from


the


main source tree and another doc:





<xsl:variable name="bothDocs" select="/|document('otherdoc.xml')"/>





Then you can refer to $bothDocs/path/to/some/nodes. The initial slash


is the root node of the main source tree; "|" means union of two node-sets,


and the document() call returns the root node of otherdoc.xml.





You can, of course, use the document() function separately to access


just that document's node tree.





-----------


software reviews