嗯,如果您仍然可以使用幫助,我很樂意幫助您編寫問題的XML部分。然而,我需要編輯XML的主題。如果我想使用字符串解析,我對如何編輯XML有一個想法,但我不知道如何去更新原始XML文件...... [對不起,如果我在那裏丟失了你。]但是我要去編輯一個適合我的代碼,這樣你就可以偷看了。 :)
易佳(對於新手,至於嘛)
閱讀在XML在Android中:-)
演示XML
<UltraSpecialEvents>
<UltraSpecialEvent Name= "USE1">
<UltraSpecialInfo Name="USI1" Detail="Blah" TimeStamp="hh:mm:ss" />
<UltraSpecialInfo Name="USI2" Detail="Blah Blahs" TimeStamp="hh:mm:ss" />
<UltraSpecialInfo Name="USI3" Detail="And More Blahs" TimeStamp="hh:mm:ss" />
</UltraSpecialEvent>
<UltraSpecialEvent Name= "UnusedGarbageStuff't">
<UltraSpecialInfo Name="USI1" Detail="Blah" TimeStamp="hh:mm:ss" />
<UltraSpecialInfo Name="USI2" Detail="Blah Blahs" TimeStamp="hh:mm:ss" />
<UltraSpecialInfo Name="USI3" Detail="And More Blahs" TimeStamp="hh:mm:ss" />
</UltraSpecialEvent>
</UltraSpecialEvents>
讀取XML
public ArrayList<ArrayList<String>> get() {
ArrayList<ArrayList<String>> classes = new ArrayList<ArrayList<String>>();
try {
boolean inTargetedTag = false;
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
parser.setInput(inputStream, null);
int eventType = parser.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
switch (eventType) {
case XmlPullParser.START_TAG:
String tagName = parser.getName();
if (tagName.equalsIgnoreCase("UltraSpecialEvent")) {
if (parser.getAttributeValue(null, "Name").equals("USE1")) {
inTargetedTag = true;
} else {
inTargetedTag = false;
}
} if (tagName.equalsIgnoreCase("UltraSpecialInfo")) {
if (inTargetedTag) {
ArrayList<String> single_Info = new ArrayList<String>();
single_Info.add(parser.getAttributeValue(null, "Name"));
single_Info.add(parser.getAttributeValue(null, "Detail"));
single_Info.add(parser.getAttributeValue(null, "TimeStamp"));
bundled_Info.add(single_Info);
}
}
break;
}
eventType = parser.next();
}
} catch (FileNotFoundException e) {
} catch (IOException e) {
} catch (Exception e) {
}
return bundled_Info;
}
希望這有助於:/