Hi im very new to webserices and xml parsing.I use http://www.mysamplecode.com/2011/11/android-parse-xml-file-example-using.html this link as my reference. But i think in this link the xml is a simple one.How can i parse a complex xml like this one.Can any one suggest me a method to parse this. I want to read the values of < A >,< B >,< C >,< D > tags from each MenuEntry
<Menu>
<MenuEntries>
<MenuEntry>
<A>--AAAAA---</A>
<B>--BBBB---</B>
<MenuEntries/>
<C>--CCCC---</C>
<D>--DDDD---</D>
</MenuEntry>
<MenuEntry>
<B>--BBBB---</B>
<menuEntries/>
<C>--CCCC---</C>
<D>--DDDD---</D>
</MenuEntry>
<MenuEntry>
<A>--AAAAA---</A>
<B>--BBBB---</B>
<MenuEntries>
<MenuEntry>
<A>--AAAAA---</A>
<B>--BBBB---</B>
<MenuEntries/>
<C>--CCCC---</C>
<D>--DDDD---</D>
</MenuEntry>
<MenuEntry>
<A>--AAAAA---</A>
<B>--BBBB---</B>
<MenuEntries/>
<C>--CCCC---</C>
<D>--DDDD---</D>
</MenuEntry>
</MenuEntries>
<C>--CCCC---</C>
<D>--DDDD---</D>
</MenuEntry>
<MenuEntry>
<B>--BBBB---</B>
<MenuEntries/>
<C>--CCCC---</C>
<D>--DDDD---</D>
</MenuEntry>
<MenuEntry>
<A>--AAAAA---</A>
<B>--BBBB---</B>
<MenuEntries>
<MenuEntry>
<A>--AAAAA---</A>
<B>--BBBB---</B>
<MenuEntries/>
<C>--CCCC---</C>
<D>--DDDD---</D>
</MenuEntry>
</MenuEntries>
<C>--CCCC---</C>
<D>--DDDD---</D>
</MenuEntry>
</MenuEntries>
</Menu>
This is my xmlHandler class for parsing the xml
public class ItemXMLHandler extends DefaultHandler {
Boolean currentElement = false;
String currentValue = "";
Menu item = null;
static ArrayList<Menu> menuList = new ArrayList<Menu>();
public static ArrayList<Menu> getMenuListz() {
Log.e("in getMenulist()", String.valueOf(menuList.size()));
return menuList;
}
// Called when tag starts
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
currentElement = true;
currentValue = "";
if (localName.equals("MenuEntry")) {
//Log.e("menuENtry found ", "menuENtry found");
item = new Menu();
}
}
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
currentElement = false;
/** set value */
if (localName.equalsIgnoreCase("A")) {
item.setA(currentValue);
} else if (localName.equalsIgnoreCase("B")) {
item.setB(Long.parseLong(currentValue));
} else if (localName.equalsIgnoreCase("C")) {
item.setC(currentValue);
} else if (localName.equalsIgnoreCase("menuEntry"))
menuList.add(item);
}
// Called to get tag characters
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
if (currentElement) {
currentValue = currentValue + new String(ch, start, length);
}
}
}
This is my java class for Menu
public Class Menu{
private long B;
private String A;
private String C;
public long getB() {
return B;
}
public void setB(long B){
this.B = B;
}
public String getA() {
return A
}
public void setA(String A){
this.A = A
}
public String getC() {
return C
}
public void setC(String C) {
this.C = C;
}
}
Im getting duplications and null values.I know my coding could be wrong can any one help me with a reply or any useful links for parsing this kind of complex xml ( for me its complex :) )