try {
XmlPullParser xpp = XmlPullParserFactory.newInstance().newPullParser();
xpp.setInput(in, "utf-8");
int event = xpp.getEventType();
while (event != XmlPullParser.END_DOCUMENT) {
switch (event) {
case XmlPullParser.START_TAG:
if (xpp.getName().equals("msg")) {
HashMap<String, String> attrs = new HashMap<String, String>();
for (int i = 0; i < xpp.getAttributeCount(); i++) {
attrs.put(xpp.getAttributeName(i), xpp.getAttributeValue(i));
}
try {
BluetoothMapMessage msg = new BluetoothMapMessage(attrs);
mMessages.add(msg);
} catch (IllegalArgumentException e) {
/* TODO: provide something more useful here */
Log.w(TAG, "Invalid <msg/>");
}
}
break;
}
event = xpp.next();
}
} catch (XmlPullParserException e) {
Log.e(TAG, "XML parser error when parsing XML", e);
} catch (IOException e) {
Log.e(TAG, "I/O error when parsing XML", e);
}