Posts

Showing posts from September, 2014
DOMParser - XML Parsing 2 In DOMParser everything is a node. A node has childNodes which might have childNodes. DOM Structure I always find DOMParser a better choice when the whole xml files need to be loaded to a single object. When doing a lot of calculations on the xml use a SAXParser. I will post in an example soon. Use a SAXParser over a DOMParser. Reason: SAXParser gives better performance. SAX is faster! DOMParser reads the whole XML File in the memory, if the file is big.. we might get Memory issues!
XML Parsing - 1 Lets start with the structure of XML first. XML is a way of storing data.. sample xml file: <?xml version="1.0" encoding="UTF-8 " ?> <person> <name>Richa</name> <age>100</age> <lastname>Vaidya</lastname> <address>India</address> </person> the first line gives the version of the xml i.e 1.0 the next line person is the root all the contents of the xml are a part of the root i.e. person the later lines.. these are the elements of the root. So now we have the data, how do we use it in a java program. Read it line by line? No... We have been provided with two excellent parsers : DOMParser and  SAXParser . Difference between DOMParser and SAXParser., DOM reads the complete xml element, so you have the complete file in the memory and you can access the elements of the DOM root at you wish. SAX parser reads the file line by line. DOM parser has a greater memo