trainingtrains Logo

91-9990449935

 0120-4256464

Android XML Parsing using DOM Parser

We can parse the xml document by dom parser also. It can be used to create and parse the xml file.

Advantage of DOM Parser over SAX

It can be used to create and parse the xml file both but SAX parser can only be used to parse the xml file.

Disadvantage of DOM Parser over SAX

It consumes more memory than SAX.


Example of android DOM Xml parsing

activity_main.xml

Drag the one textview from the pallete. Now the activity_main.xml file will look like this:

File: activity_main.xml

xml document

Create an xml file named file.xml inside the assets directory of your project.

File: file.xml

Activity class

Let's write the code to parse the xml using dom parser.

File: MainActivity.java


Output:

DOM Xml Parsing