I have this XML:
<menu>
<day name="monday">
<meal name="BREAKFAST">
<counter name="Bread">
<dish>
<name>Plain Bagel</name>
</dish>
<counter/>
<meal/>
<day/>
<day name="tuesday">
<meal name="LUNCH">
<counter name="Other">
<dish>
<name>Cheese Bagel</name>
</dish>
<counter/>
<meal/>
<day/>
<menu/>
Now here is what I am trying to do, if the day tag's attribute is equal to monday. And then meals tag attribute is equal to BREAKFAST
, then I want to get the counter's attribute. "Bread".
I have set up xml pull parser, but I am struggling getting this value. Here is what I have tried, I now I see that it can't and won't work... So any help on how I could set it up to do this would be great.
while (eventType != XmlResourceParser.END_DOCUMENT) {
String tagName = xmlData.getName();
switch (eventType) {
case XmlResourceParser.START_TAG:
if (tagName.equalsIgnoreCase("day")) {
if (xmlData.getAttributeValue(null, "name").equalsIgnoreCase(day)) {
if (tagName.equalsIgnoreCase("meal")) {
mealArray.add(xmlData.getAttributeValue(null, "name"));
Log.i(TAG, xmlData.getAttributeValue(null, "name"));
}
}
}
break;
case XmlResourceParser.TEXT:
break;
case XmlPullParser.END_TAG:
break;
}
eventType = xmlData.next();
}