This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Merging XML documents - use DOM or XSLT? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Merging XML documents - use DOM or XSLT?" Watch "Merging XML documents - use DOM or XSLT?" New topic
Author

Merging XML documents - use DOM or XSLT?

sam shah
Greenhorn

Joined: Aug 06, 2001
Posts: 4
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

Joined: Aug 26, 2000
Posts: 10065
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

Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
Suresh Bansal
Ranch Hand

Joined: Jul 23, 2001
Posts: 91
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.


Journey is as important as the Destination.<br /> <br />PMP, SCJP, SCJD, SCEA (Part 1), SCMAD, SCDJWS
sam shah
Greenhorn

Joined: Aug 06, 2001
Posts: 4
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

Joined: Aug 26, 2000
Posts: 10065
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

Joined: Aug 06, 2001
Posts: 4
Thanks for your help! I think i shall have to use DOM, given the lack of time
Sam
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Merging XML documents - use DOM or XSLT?
 
Similar Threads
Difference Xerces and Xalan
Newbie Question
When not to use Ajax?
XML Certification Stuff
Merging XML documents with DOM