File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Merging XML documents - use DOM or XSLT?

 
sam shah
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing an app to merge XML documents and have to decide on using either DOM or XSLT. What are the benefits of one over the other? I will be merging many documents.
thanks
Sam
 
Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would say if your merging logic is not too complex and doesn't depend on run-time information too much, XSLT is a good choice. Otherwise, DOM is preferable. There are two links about merging XML documents with XSLT, just in case
Merging XML Documents http://devguy.com/fp/XML/XSL/Merge/
Use XSLT to Merge XML Documents, by A. Russell Jones http://www.xmlmag.com/upload/free/features/xml/2001/06jun01/rj0103/rj0103.asp
 
Suresh Bansal
Ranch Hand
Posts: 91
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I beleive XSLT will be a better choice as its faster and suits the requirements, but you may find DOM easier to use/implement your logic.
 
sam shah
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the replies. The app will be merging data from different sources, but a requirement is also to be able to choose what elements to include or not in the final document ( some elements are removed if user decides not needed). this is making it more complex, so maybe DOM is the road to go down?
I am a novice to XSLT, so how straightforward is it to write a template that can then be applied to other XML documents ( with different elements) to do the merging without making many changes?
many thanks for your help
 
Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It may take a while, maybe a month or two, to become comfortable with XSLT's way of thinking. After that, it will be probably easier to solve problems with XSLT then with DOM. However, if your project has to be finished, as usual, yesterday and you do not have this time or you do not plan to use XSLT after this single project, then learning XSLT may be overhead.
how straightforward is it to write a template that can then be applied to other XML documents
Typically in XSLT stylesheet we specify concrete elements, so writing a generic XSLT is not really straightforward. You can use such patterns as
node() - match any element
//*[name()=$elementName] - match elements with a name specified in the elementName variable
there are a lot of useful recipes on http://www.dpawson.co.uk/xsl/sect2/sect21.html - in case you will decide to use XSLT.
a requirement is also to be able to choose what elements to include or not in the final document (some elements are removed if user decides not needed).
This will also complicate your XSLT. Not that it is impossible, but there is no way to communicate with a user "from" XSLT at run-time. You can either pass a user choice as a parameter to XSLT stylesheet, or to put it in another XML file (XSLT accepts only XML documents as an input) and make your XSLT read second XML document via document('filename.xml') function.

[This message has been edited by Mapraputa Is (edited August 07, 2001).]
 
sam shah
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help! I think i shall have to use DOM, given the lack of time
Sam
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic