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 memory print than SAX parser.

Use of DOM or SAX should be dependent on the need of the application.

Comments

Popular posts from this blog

Writing your own ejabberd Module

npm ECONNREFUSED error

Conditional Flow - Spring Batch Part 6