我有XML文件,例如:
<?xml version="1.0" encoding="utf-8"?>
<Fields>
<Field name="rampam" />
<Field name="rampampam" />
</Fields>
<NotFields>
<Field name="testName1" />
<Field name="testName2" />
</NotFields>
我希望阅读{Fields}下Field
的所有name
属性值。我试过这段代码:
static public void getInputFields(
XmlResourceParser parseXML) throws XmlPullParserException,
IOException {
int eventType = -1;
while (eventType != XmlResourceParser.END_DOCUMENT) {
if (eventType == XmlResourceParser.START_TAG) {
if (parseXML.getName().equals("Fields")) {
parseXML.next();
while (parseXML.getName().equals("Field")) {
String fieldName = parseXML.getAttributeValue(null,
"name");
parseXML.next();
}
}
}
eventType = parseXML.next();
}
}
它首先读取Field
,但在它从getAttributeValue()
获取空值后,我错过了什么?
P.S。我是解析xmls的新手。