0

私はこの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そして、 attribute の排他的な値を持つすべての子タグを読み取りたい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();
    }
}

誰でも助けることができますか?

4

1 に答える 1