I am reading from an XML file using XML Parser.
XML Parser is reading the first line as null and then returns other data from the xml file so created.
Following is the XML Parsing Code:
XmlResourceParser parser = getResources().getXml(R.xml.contacts);
int eventType = -1;
try {
while (eventType != XmlResourceParser.END_DOCUMENT)
{
if(eventType == XmlResourceParser.START_TAG)
{
if(parser.getName().toString().equals("contact") && parser.getName().toString().equals("null"))
col.append(parser.getAttributeValue(null, "name") + "\n");
col.append(parser.getAttributeValue(null, "phone") + "\n \n");
}
eventType = parser.next();
}
}
catch (XmlPullParserException e) {
e.printStackTrace();
}
Following is the XML File:
<?xml version="1.0" encoding="utf-8"?>
<contacts>
<contact name="Prathama Blood Center" phone="079 26600101" />
<contact name="Green Cross" phone="079 25507013"/>
<contact name="Crossworld Blood Bank" phone="079 26568004"/>
<contact name="Adarsh Voluntary Blood Bank" phone="079 22746672"/>
<contact name="Red Cross" phone="079 27551790"/>
</contacts>
Following is the Screen I am getting: