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.
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).
Joined: Jun 15, 2001
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?
Joined: Mar 17, 2000
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.