Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sample DOM/SAX Question #4

 
Jeff X Williams
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 X Williams
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
If you want to create a subtree of main tree, you can check JDOM API.
Hari
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 X Williams
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic