1

次のコードを使用して XML を解析しています。公式の Android ドキュメントから参照されています。

XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();

xpp.setInput(new StringReader(response));
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
    if (eventType == XmlPullParser.START_DOCUMENT) {
        System.out.println("Start document");
    } else if (eventType == XmlPullParser.START_TAG) {
        System.out.println("Start tag " + xpp.getName());
    } else if (eventType == XmlPullParser.END_TAG) {
        System.out.println("End tag " + xpp.getName());
    } else if (eventType == XmlPullParser.TEXT) {
    //    System.out.println("Text " + xpp.getText());



    }
    eventType = xpp.next();
}
System.out.println("End document");

コンソールで:

06-08 11:13:25.557  24857-24883/ex.com.receipts I/System.out﹕ Start document
06-08 11:13:25.557  24857-24883/ex.com.receipts I/System.out﹕ Start tag exareceipts
06-08 11:13:25.557  24857-24883/ex.com.receipts I/System.out﹕ Start tag email
06-08 11:13:25.557  24857-24883/ex.com.receipts I/System.out﹕ End tag email
06-08 11:13:25.557  24857-24883/ex.com.receipts I/System.out﹕ Start tag authentication_status
06-08 11:13:25.557  24857-24883/ex.com.receipts I/System.out﹕ End tag authentication_status
06-08 11:13:25.557  24857-24883/ex.com.receipts I/System.out﹕ End tag exareceipts
06-08 11:13:25.557  24857-24883/ex.com.receipts I/System.out﹕ End document

ただし、この名前のノードにのみ関心があるauthentication_statusため、確認する必要があることがわかっています。

if(xpp.getName().equalsIgnoreCase("authentication_status")){
    //logic for getting node value
}

私は本当に混乱していて確信が持てません - このコードをどこに置くべきか.

4

1 に答える 1