-Consider a system which is memory & speed constraint. The application is to process XML documents, sort the contents and mail them to a higher configuration machine for transformation. Which is the best approach? a) Use platform native language to process the docuements b) Use DOM based approach. c) Using SAX based approach is the best. d) DOM and SAX must be used in this context.
Answer : b -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. Answers : b If memory is a concern, why don't we use SAX? DOM will load the whole document into memory, right? [ September 10, 2002: Message edited by: jim yin ]
Jim, I think that the following clippings matter here - "application has to sort the contents" "application has to extract part of the document" Hence if we are to do something with the content, the only way we can do it is using DOM. Sax just walks thru the document and i think it gets extremely painful(too many criterion to take into account w.r.t the xml tree) if we are to extract a part of the contents in the process. My only concern here is why not XSLT to extract part of the document, which i guess is pretty fast than the DOM based approach; I guess we can run a xsl-stylesheet on the xml instance document from within our application, but again we have to hold the data in buffer in order to play with it and hence again DOM.
Dom is the best approach in both the cases. In first case,DOM is used since you need to sort the contents and in the second one you need to extract few information. SAX does not provide random search.So if you need to extract very few data ,SAX will follow a sequential order in searching for the required content,whereas with DOM you can directly search the needed information. As far as XSLT is concerned,the XSLT processors hold all data in memory while transformation is taking place and eventually the tree structure may be almost 10 times the data size. Since the data file specified in the quesion is large,so finally DOM would be the best approach.
Hope this help. Vasudha
IBM Certified Developer -XML and Related Technologies(141)<br />SCJP2 SCWCD
hi, DOM is best in first case but in second case answer may be SAX. Because in second case application has to extract very few information and memory & speed may be a constrain."SAX or DOM" depends on which type of data u want to extract from document. <userinfo> <user name="Ronak"> <age>22</age> <address>Ahmedabad</address> </user> <user name="David"> <age>52</age> <address>New york</address> </user> <user name="Mahesh"> <age>32</age> <address>Baroda</address> </user> </userinfo>
SAX is best for following searching like -> find user name and its age where username like ="Ro%" -> average age of all user -> list all user and their address DOM is best for following searching like -> list all username whose age is belove than average age (for this u have to first calculate average and than u can take decision)
These are poorly written questions because they give conflicting requirements and wrong answers. The real exam is not quite this bad. If the question states that performance and/or memory are a big concern then the answer is almost certainly going to be SAX. The author of the question (I guess) would say that performance and memory are secondary to the other requirement, but I would say that if you don't have enough memory to load the document using DOM, then nothing else matters. You CAN sort using SAX (might be hard, but possible) and you CAN search for a few elements using SAX (may actually be more efficient than DOM anyway), but if you don't have enough memory to load the document using DOM then you CAN'T sort and you CAN'T search for a few items. So, the bottom line is the answers given to these sample questions are WRONG! There really aren't any good sample exams that don't contain bad questions like these and are similar to the IBM style of questions. The closest is the IBM sample XML exam.