Ways of parsing xml document, DOT NET Programming

What are the ways of parsing XML document?

The XML parser sits in between the XML document and the application who want to use the XML document. The Parser exposes a set of well defined interfaces which can be used by the application for adding, deleting, and   modifying the XML document contents. Now whatever interfaces XML parser exposes must be standard or else that would lead to different Vendors preparing their own custom way of interacting with the XML document.

There are 2 standard specifications which are very common and should be followed by a XML parser:-

DOM: - Document Object Model.

The DOM is a W3C recommended way for treating XML documents. In DOM we load the whole XML document into memory and allow us to manipulate the structure and data of XML document.

SAX: - Simple API for XML.

The SAX is an event driven way for processing XML documents. In the DOM we load the entire XML document into memory and then application manipulates the XML document. But this is not always the best way to process large XML documents which have huge data elements. For illustrate  you only want one element from the entire XML document or you only want to see if the XML is proper that  means loading the whole XML in memory will be quiet resource intensive. The SAX parsers parse the XML document sequentially and emit events such as start and end of the document, elements, text content etc. Therefore the applications who are interested in processing these events can register implementations of callback interfaces. The SAX parser then only sends those event messages which the application has demanded.

56_DOM.png

Figure: - DOM Parser loading XML document

The above is a pictorial representation of how a DOM parser works. The application queries the DOM Parser for the "quantity" field. The DOM parser loads the complete XML file into the memory.

1262_DOM1.png

Figure: - Returning the Quantity value back to application

The DOM parser then picks up the "quantity" tag from the memory loaded XML file and then returns back to the application.

2241_DOM2.png

Figure: - SAX parser in action

The SAX parser does not load the entire DOM into memory but has event based approach. The SAX parser while parsing the XML file emits events. For e.g. in the above figure it has emitted Invoice tag start event, Quantity tag event , Amount Tag event, and Invoice end tag event. But our application software is only interested in the quantity value. Hence the application has to register to the SAX parser saying that he is only interested in the quantity field and not any other field or element of the XML document. Depending on what interest the application software has SAX parser only sends those events to the application, the rest of events is suppressed. For illustrate in the above figure only quantity tag event is sent to the application software and the rest of the events are suppressed.

Posted Date: 9/25/2012 2:49:15 AM | Location : United States







Related Discussions:- Ways of parsing xml document, Assignment Help, Ask Question on Ways of parsing xml document, Get Answer, Expert's Help, Ways of parsing xml document Discussions

Write discussion on Ways of parsing xml document
Your posts are moderated
Related Questions
What is marshalling and types of marshalling? The Marshaling is used when an object is converted so that it can be sent across the network or across the application domains. Th

I need help figuring out how to capture text box values from C# ASP.NET and send them from one class to another after being processed by a method.

I need Programmer to extracting data Project Description: Programmer role A skilled programmer is required to build a standalone module to extract, parse and store in data

What is a class? A class describes all the attributes of objects, as well as the methods that execute the behaviour of member objects. It is a comprehensive data type, which sh

We need Long term Kentico developer needed I want a solid Kentico developer that I can rely on to handle overflow work. Usually this will include about 5 hours of work each week

What is the difference between thread and process? The thread is a path of execution which can run on CPU; a process is a collection of threads that share the same virtual memo

The project aims at converting a rough hand drawn diagram to a neat diagram. Is it a good project for B.Tech level?Please tell how to go about it??

What is Reflection?  It extends the advantages of metadata by allowing developers to inspect and use it at runtime. For example, dynamically determine all the classes contained

I need Web Based Inventory Management System Project Description: I require a build in software which has the subsequent features, if anybody has ready to use web based appli

Question: (a) Give four benefits of ASP.NET Web Controls. (b) List and explain any five properties of the ValidationSummary control. (c) Multiple Web Form controls ca