Hallo,
ich habe folgendes XML Schema (wurde nachträglich erweitert)
Code
notifications>
<status>
<ack>OK</ack>
<errormessage/>
<amount>2</amount>
<maxid>8</maxid>
</status>
<notification>
<id>6</id>
<title>Termin-Erinnerung</title>
<description>dfgdfg</description>
<type>kalendertermin</type>
<date>2014-07-08 13:53:53.0</date>
<creator>Patrick Demo</creator>
<time>2014-07-08 12:50:00.0</time>
</notification>
<notification>
<id>8</id>
<title>Termin-Erinnerung</title>
<description>HubaBuba Termin</description>
<type>kalendertermin</type>
<date>2014-07-08 14:11:12.0</date>
<creator>Patrick Demo</creator>
<time>2014-07-10 14:30:00.0</time>
</notification>
</notifications>
Alles anzeigen
Dazu habe ich folgenden Java-Code:
Code
private void parseXML(XmlPullParser parser) throws XmlPullParserException, IOException {
int eventType = parser.getEventType();
Notification currentNotification = null;
while (eventType != XmlPullParser.END_DOCUMENT) {
String name = null;
switch (eventType) {
case XmlPullParser.START_DOCUMENT:
this.notes = new ArrayList<Notification>();
break;
case XmlPullParser.START_TAG:
name = parser.getName();
if (name.equalsIgnoreCase("notification")) {
currentNotification = new Notification();
} else if (currentNotification != null) {
if (name.equalsIgnoreCase("id")) {
currentNotification.id = Integer.parseInt(parser.nextText());
} else if (name.equalsIgnoreCase("title")) {
currentNotification.title = parser.nextText();
} else if (name.equalsIgnoreCase("description")) {
currentNotification.description = parser.nextText();
} else if (name.equalsIgnoreCase("type")) {
currentNotification.type = parser.nextText();
} else if (name.equalsIgnoreCase("creator")) {
currentNotification.creator = parser.nextText();
} else if (name.equalsIgnoreCase("time")){
try {
String testTime = parser.nextText();
if (testTime != null && !testTime.equals("")){
SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
currentNotification.time = simpleDateFormat2.parse(testTime);
}else{
currentNotification.time = null;
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (name.equalsIgnoreCase("date")) {
try {
currentNotification.date = new SimpleDateFormat("yyyy-MM-dd").parse(parser.nextText());
}
catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
break;
case XmlPullParser.END_TAG:
name = parser.getName();
if (name.equalsIgnoreCase("notification")
&& currentNotification != null) {
notes.add(currentNotification);
}
}
eventType = parser.next();
}
}
Alles anzeigen
wie kann ich nun den Code umbauen, dass ich an die Elemente aus <status> ran kommen. Diese werden zwar benötigt, aber nicht um in der ListView angezeigt zu werden. Brauche diese Daten zur internen Verarbeitung.