【发布时间】:2013-04-16 13:30:06
【问题描述】:
我有这个 xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<Products>
<Product productName="testProduct1">
<Fields>
<Field name="Stack" />
<Field name="Overflow" />
</Fields>
<AnotherFields>
<Field name="Test" />
</AnotherFields>
</Product>
<Product productName="testProduct">
<Fields>
<Field name="StackOverflow" />
</Fields>
</Product>
</Products>
并且要读取product 的所有子标签,它具有属性productName 的独占值,所有其他标签都想跳过。
这是我卡住的java代码:
public void mainParser(XmlResourceParser configXML, String productNameParameter)
throws XmlPullParserException, IOException {
int eventType = -1;
String strName, productName;
while (eventType != XmlResourceParser.END_DOCUMENT) {
if (eventType == XmlResourceParser.START_TAG) {
strName = configXML.getName();
if (strName.equals("Product")) {
if (eventType == XmlResourceParser.START_TAG) {
productName = configXML.getAttributeValue(null, "productName");
if (productName.equals(productNameParameter)) {
eventType = configXML.next();
//here is the problem
}
}
}
}
eventType = configXML.next();
}
}
谁能帮忙?
【问题讨论】:
标签: android xml xml-parsing xmlpullparser