Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to merge two documents in memory

 
mathew Jackson
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5782
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
mathew Jackson
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5782
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic