我在解析 android 中的 XML 时遇到了困难。我有以下 XML
<iq xmlns="jabber:client" type="result" to="blob@faisal-system/68bb97e7">
<album xmlns="naseebalbum">
<albumpicture>
<title>day1</title>
<creationdate>1397502000000</creationdate>
<picture>BASE64EncodedStringOfImage</picture>
</albumpicture>
<comments>
<comment>
<commentid>1</commentid>
<username>sana</username>
<text>i loved that pic</text>
<commenttime>1398264140000</commenttime>
</comment>
</comments>
<likes>
<like>
<likeid>4</likeid>
<username>sana</username>
<liketime>1398250919000</liketime>
</like>
</likes>
</album>
</iq>
有人可以帮我吗?
我想从喜欢标签评论标签标题标签和图片标签中获取数据。
这是我一直在尝试做的事情。
public IQ parseIQ(XmlPullParser parser) throws Exception {
// TODO Auto-generated method stub
payload=""+parser.getText();
StringBuilder sb = new StringBuilder();
int depth = 1;
while (depth != 0) {
switch (parser.next()) {
case XmlPullParser.END_TAG:
depth--;
if (depth > 0) {
sb.append("</" + parser.getName() + ">");
}
break;
case XmlPullParser.START_TAG:
depth++;
StringBuilder attrs = new StringBuilder();
for (int i = 0; i < parser.getAttributeCount(); i++) {
attrs.append(parser.getAttributeName(i) + "=\""
+ parser.getAttributeValue(i) + "\" ");
}
sb.append("<" + parser.getName() + " " + attrs.toString() + ">");
break;
default:
sb.append(parser.getText());
break;
}
}
payload = sb.toString();
iq=new CustomIQ(payload);
iq.setType(Type.RESULT);
return iq;
}