aspose file tools*
The moose likes Product and Other Certifications and the fly likes Sample DOM/SAX Question #4 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Product and Other Certifications
Bookmark "Sample DOM/SAX Question #4" Watch "Sample DOM/SAX Question #4" New topic
Author

Sample DOM/SAX Question #4

Jeff Williams
Greenhorn

Joined: Sep 28, 2001
Posts: 29
The following question is from the DOM/SAX sample exam on this site. It gives the answer as (b), but there is no way that can be right. Everything I have read says SAX is to be used when memory and performance are a concern. Am I misreading the question, or does this sample exam just suck?
4. There is XML data document which is very large. The application is to extract the very few of its information from document. The memory & speed may be a constraint. Which is the most likely method to be implemented?
a) Extract the information using SAX API, event based methods.
b) To extract the information using DOM API.
c) To extract the necessary information and process using XSLT.
d) To use schema based approach.
Hari babu
Ranch Hand

Joined: Jun 25, 2001
Posts: 208
Hi jeff,
The requirement is "The application is to extract the very few of its information from document". To do this we either make use of XSLT/XPATH or DOM,because using SAX you cant search thru a document, as SAX doesnt know about its parent/child/siblings. So out of the above choices, you choose either (b) or (c). (C) in turn uses (b). So the answer is (b). Of course i know everyone goes with the phrase "The memory & speed may be a constraint" which rules out DOM, but our first aim to solve the problem and then choose the best method.
Hope this helps
Hari
Jeff Williams
Greenhorn

Joined: Sep 28, 2001
Posts: 29
I disagree. SAX can't give you random access, but you can still search for a particular element. If this question was meant to imply a requirement for random access, it failed to. I can only hope the real test is written much better than this. I'll find out tomorrow when I take the exam.
Hari babu
Ranch Hand

Joined: Jun 25, 2001
Posts: 208
Hi,
Yes using SAX you can search for a element, But remeber the constraint (speed),If you are using SAX u need to compromise on speed. Ofcourse i agree that using DOM (and also the document is huge) we are eating more memory,but out of the given choices, for me DOM seems to be better option which satisfies the requirment and constraint.
Anyone has diffrent opinion ?
Hari
Jayadev Pulaparty
Ranch Hand

Joined: Mar 25, 2002
Posts: 662
If the fact that SAX processing is slower than DOM is true(i'm not aware of this; just a novice to XML), i'll agree with Hari. We can always generate another sub-DOM as per the requirement to work upon, from the main DOM, and get rid of the main one. This way we may not need to persist the entire document in DOM for the entire session.
Also, the fact that we can arrive at a specific element using SAX may not be straight-forward. We may need to keep track of the ancestor info in our program for the purpose.
Hari babu
Ranch Hand

Joined: Jun 25, 2001
Posts: 208
Hi,
If you want to create a subtree of main tree, you can check JDOM API.
Hari
Jayadev Pulaparty
Ranch Hand

Joined: Mar 25, 2002
Posts: 662
I was thinking of the sub-tree creation as an optimization path to address the following statement -
"The application is to extract the very few of its information from document"
This few info can always be persisted in a sub-tree to be traversed upon and also keeps the DOM light weight in memory
Jeff Williams
Greenhorn

Joined: Sep 28, 2001
Posts: 29
According to Pro XML 2, SAX is twice as fast as DOM, and uses 1/10 the memory so I still think the answer given for this question is wrong.
Jayadev Pulaparty
Ranch Hand

Joined: Mar 25, 2002
Posts: 662
Jeff,
Little info... I have Prof XML 1 (old edition); Is it ok to continue with that w.r.t understanding the DOM/SAX API or there is some important additional info provided in the second edition. Please let me know.
Regards,
Jayadev.
Hari babu
Ranch Hand

Joined: Jun 25, 2001
Posts: 208
Hi,
I disagree, because SAX cant be faster than DOM when your searching for a particular value. Yes the memory requirments is more, but speed
Any thoughts ?
Hari
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Sample DOM/SAX Question #4