• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

how to merge two documents in memory

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Anything worth doing well is worth doing poorly first. Just look at this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic