This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Can nayone please help me to get out of this confusion. I have been reading XML / CSS /XSL for some time now. And am clear that when we apply stylesheets to XML document we can get the o/p on any of the media we want ay browser or printout applying appropriate stylesheets. Noe I read DOM examples which are reading the xml data and displaying it as HTML document. So suddenly I felt hey then why use DOM/SAX api's with scripting languages!! Now I am feeling confused again. I understand these examples are just doing this displaying thing which can very well be done with stylesheets. But may be for writing to and from database I have to use these APIs. May be I need to have look at some other examples by which I will clearly understand the use of DOM. Please help me clarify my confusion. I know my doubt is stupid :-( but then where else but such free forum to ask this!! Thanks
Joined: Jan 04, 2001
I mean where we can express our stupidity.... Else I feel concious to ask some of the doubts..to someone Here everyone seems to be free and understanding.
Gemini, your doubt is not stupid at all. All too often can we do the same things with both DOM/SAX and XSLT. It's not so obvious which technology is preferable: as usual, there are pro and contra for both. Decision depends on 1) what kind of processing we need to apply 3) what are performance requirements 3) which language we are more comfortable with I think if the task is to present XML document by converting it to HTML or some other format, then it's better to use XSLT. To hardcode presentation information in a program, working with DOM, is also possible, but it's not the best solution. In this case it's much easier to use XSL(T) and we also have advantage of separating data and presentation layers. If the task is to to transform our XML document, say, to select only specific nodes or re-arrange/sort them, then we again have both options: DOM/SAX or XSLT. XSLT language was specially designed for XML transformation, and it's often easier to use than Java+DOM+SAX. But in my feeling there are three moments to consider: 1) XSLT doesn't give us as much control on the document as we may want 2) XSLT programs do not scale well. If we can solve our problems with one-page-XSLT, then it's fine. But if we have complicated data and complex processing logic, then our XSLT quickly became unreadable. There are tools for modularity/reuse in XSLT, but in my opinion (which may be wrong!) object-oriented languages fight complexity better. 3) XSLT as a language is different from procedural languages, we used to. It is a functional language and people often find it difficult to understand. For example, we cannot update variables and simple construction I=I+1 doesn't work with XSLT. This article wil give more information. Regarding performance requirements, XSLT again doesn't give us too much control, we have to rely on XSLT processor optimization mechanism. (Of course, in typical cases XSLT processor may do a better job than an average programmer ) Most of XSLT processors use DOM to represent an XML tree, so they are not very good for really large documents. There is an exception, however, Saxon, which accepts SAX events as an input. Bottom line: if you have small XML files without complex processing, XSLT is the best choice. If your files are large, or can become large then you may consider �real pogramming� with DOM/SAX or at least, choose your XSLT processor more carefully. I know that Ajith favours DOM/SAX, so I would wait for his reply
Leverager of our synergies
Joined: Aug 26, 2000
Joined: Jan 04, 2001
Thanks about taking time to guide me in my skills. Presently I am planning to take up XML certification. and as this site helped me for my java certification hangging around a lot out here... Thanks a lot.