Monday, 24 May 2010

PWS HW1 - SAX XML Parser

As DOM, SAX is a XML parser. The difference between DOM and SAX is while DOM create a tree and save the structure of the tree in its memory, SAX reset its memory when it find new element to parse.

SAX stand for Simple API for XML. Here you can find more information about it:

I have described the design of the structure here:

http://switchyourcodinglife.blogspot.com/2010/05/pws-hw1-sax-parser-structure.html

Mainly the parser has tree methods: StartElement, Character and endElement. The example I used is: yourName

1. StartElement:
This method is called when the parser find the first tag (e.g. ) of the XML element. The important thing here is the "arg2", which contain the name of the tag.

2. Character
This method is called when the parser find the element between tags (e.g. yourName). It contains the value of the element. So, what you can do is keep it into some variable.

3. endElement
This method is called when the parser find the close tag (e.g.:
). That means the parser has arrived to the final of the XML element. Now you have to decide what are you going to do with the XML element. Note that when you have nested XML element, this methods is called too. So, be careful

No comments:

Post a Comment