File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes how to merge two documents in memory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "how to merge two documents in memory" Watch "how to merge two documents in memory" New topic
Author

how to merge two documents in memory

mathew Jackson
Greenhorn

Joined: Jun 15, 2001
Posts: 12
This may be a simple question or it may be a really tough one.
I have two xml documents that have been created and sent via servlets to another java app. I need to merge data from one document into the other without storing either to disk.
I know how to use the document() function if the document called is saved somewhere but how can I do it if they are both in memory?
Any help would be appriciated.
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Assuming you have two documents in memory say document1 and document2, parsed as DOM trees, here's the code that will merge the documents

Hope that helps!


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
mathew Jackson
Greenhorn

Joined: Jun 15, 2001
Posts: 12
I wish my problem were that simple. I need to basically pass one document through an xslt. In the xslt is a call to document(). what I need is to make that call to document() to a doc in memory rather than to one at a uri.
Instead of:
<xsl:variable name="myDoc" select="http://www.document.com"/>
I need:
<xsl:variable name="myDoc" select="SOME DOC VARIABLE IN THE APP"/>
Any one?
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Sounds to me like you will have to perform in-memory transformation. Merge the two documents as I suggested in the above step. Then create a DOMSource with the root node.

Use the JAXPTransformer class, or for that matter any XSLT to apply the stylesheet in memory to obtain a DOMResult.
Checkout JAXP download for example programs.
Alternatively, you can use a publishing framework such as Cocoon to do in-memory tranformations.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to merge two documents in memory
 
Similar Threads
Calling XML Docs
Merging XML documents
RTF Merge
Regarding the IText API
Is there a way to merge 2 RTF document?