| Site Map | WizTools.org | jCraze Blog |
![]()
|
XML ParsersXML was developed for enabling high portability of data. XML is structured in such a way that programs called <XML Parsers> can read and display data in multitude formats. Modern web browsers like Mozilla and Internet Explorer have parsing capabilities inbuilt. XML Parsers may be classified as:
SAX ParserSAX refers to "Simple Application Programming Interface for XML". SAX parsers are also known as event-based parsers. How SAX WorksSAX parser reads an XML document sequentially and whenever data in the form of entity, text, CDATA are encountered, the corresponding event handler is invoked (thus the name "Event-based parser"). ExampleTake the example of this small XML document: <?xml version="1.0"?> <favactress> <name>Drew Barrymore</name> <name>Sharon Stone</name> <name>Catherine Zeta Zones</name> </favactress> The prototype SAX functions that will parse the above XML is given below (this is just a prototype, this is not based on any one particular language):
function parse_start_tag (tag_name, attributes[]){
print ("Start Element: " + tag_name);
}
function parse_end_tag (tag_name){
print ("End Element: " + tag_name);
}
function parse_text (data){
print ("Data: " + data);
}
Note:
When the parser having the above prototype is run on the XML document, the result we get is: Start element: favactress Start element: name Data: Drew Barrymore End element: name Start element: name Data: Sharon Stone End element: name Start element: name Data: Catherine Zeta Zones End element: name End element: favactress DOM ParserThe DOM parser creates an internal tree structure of the XML document. This allows the DOM parser to read, add, delete and update XML documents. This is unlike SAX parser, which has only read only access to XML documents. DOM parser also allows random access to data. <?xml version="1.0"?> <favactress> <actress> <name>Drew Barrymore</name> <favmovie>Poison Ivy</favmovie> </actress> <actress> <name>Sharon Stone</name> <favmovie>Basic Instinct</favmovie> </actress> </favactress> When a DOM parser parses the above document, it will create a tree structure internally similar to: favactress | |---actress | |--name | | |--Text | |--favmovie | | |--Text | |---actress | |--name | | |--Text | |--favmovie | | |--Text | As you can see, using the DOM architecture, every aspect of the XML document is available for read, update and write operations. Comparison: SAX & DOM Parsers
|
Sign Guestbook
|
Who is Subhash?
The contents of this site are copyright© 2000-2008, indiWiz.com. All Rights Reserved.