How to parse this kind of XML in android

I can use SAX, XMLPullParser, I can parse generalized format's data. But i am struggling to parse this formatted XML data like below:

<?xml version="1.0" encoding="utf-8"?>
<Data Branch="True" >
BranchOpeningDate="01/01/1990 00:00:00"
Name="Dhaperhat" />


It seems you don't know how to parse the attributes of the nodes.

With DOM parser, you can use the getAttributes() method of a Node to access the attributes, with SAX parser you can use getAttributeValue() of the XmlPullParser class.


The steps for parsing an XML feed are as follows:

01 .As described in Analyze the Feed, identify the tags you want to include
in your app. This example extracts data for the entry tag and its nested
tags title, link, and summary.

02 .Create the following methods:
-> A "read" method for each tag you're interested in. For example,
readEntry(), readTitle(), and so on. The parser reads tags from
the input stream. When it encounters a tag named entry, title,
link or summary, it calls the appropriate method for that tag.
Otherwise, it skips the tag.
-> Methods to extract data for each different type of tag and to advance
the parser to the next tag.For example:

* For the title and summary tags, the parser calls readText().
This method extracts data for these tags by calling

* For the link tag, the parser extracts data for links by first
determining if the link is the kind it's interested in. Then it
parser.getAttributeValue() to extract the link's value.

* For the entry tag, the parser calls readEntry(). This method
parses the entry's nested tags and returns an Entry object with
the data members title, link, and summary.

-> A helper skip() method that's recursive. For more discussion of this
topic, see Skip Tags You Don't Care About.This snippet shows how the
parser parses entries, titles, links, and summaries.


Check out this link, it will provide automated class which will parse your all xml data. The site has generator which will generate java classes which you can use in your project.

Check this link


I solved this through SAX and DefaultHandler,

public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
currentElement = true;
db = new DatabaseHelper(thecontext);
if (qName.equals("Asa.Amms.Data.Entity.User")) {
int length = attributes.getLength();
for (int i = 0; i < length; i++) {
String name = attributes.getQName(i);
if (name.equals("Id")) {
id = Integer.parseInt(attributes.getValue(i));
if (name.equals("Login")) {
LoginID = attributes.getValue(i).toString();
if (name.equals("Name")) {
Name = attributes.getValue(i).toString();
if (name.equals("Password")) {
Password = attributes.getValue(i).toString();
if (name.equals("ProgramOfficerId")) {
user_ProgramOfficerId = Integer.parseInt(attributes.getValue(i).toString());
Log.i("Baal dhukbe", id + LoginID + Name + Password);

db.insertUser(id, LoginID, Name, Password, user_ProgramOfficerId);