Я PHP программист и в разработке под Android я начинающий, но есть огромное желание освоить все что смогу запомнить..
Я пытаюсь распарсить xml файл из res/xml Его содержимое:
Код: Выделить всё
<?xml version="1.0" encoding="utf-8"?>
<countriesTag>
<cntryTag>
<mainText value="sometext1" />
<secondString value="sometext2" />
<mcc value="1" />
</cntryTag>
<cntryTag>
<mainText value="sometext3" />
<secondString value="sometext4" />
<mcc value="2" />
</cntryTag>
</countriesTag>
Код: Выделить всё
public static final String CS_TAG = "countriesTag";
public static final String MAIN_TEXT_TAG = "mainText";
public static final String SECOND_TEXT_TAG = "secondString";
public static final String TAG_ID = "mcc";
public static final String TEXTS_TAG = "cntryTag";
Код: Выделить всё
public static HashMap<String, HashMap<String, String>> getTexts(final XmlResourceParser xmlResourceParser) throws IOException {
while (true) {
final HashMap<String, HashMap<String, String>> hashMap = new HashMap<String, HashMap<String, String>>();
while (true) {
String attributeValue = null;
Label_0207: {
try {
HashMap<String, String> hashMap2 = new HashMap<String, String>();
int i = 0;
final String s = "";
new String();
while (i != 1) {
final String name = xmlResourceParser.getName();
if (i != 0) {
if (i == 2) {
Log.d("DEBUG", "Start Tag Parsing: " + xmlResourceParser.getName());
if (!name.equals("countriesTag") && !name.equals("cntryTag")) {
attributeValue = xmlResourceParser.getAttributeValue(0);
if (name.equals("mcc")) {
break Label_0207;
}
hashMap2.put(name, attributeValue);
}
}
else if (i == 3 && name.equalsIgnoreCase("cntryTag")) {
hashMap.put(s, new HashMap<String, String>(hashMap2));
hashMap2 = new HashMap<String, String>();
}
}
i = xmlResourceParser.next();
}
return hashMap;
}
catch (XmlPullParserException ex) {
return hashMap;
}
finally {
xmlResourceParser.close();
}
}
final String s = attributeValue;
continue;
}
}
}Помогите разобраться начинающему.