Search code examples
androidxmlpullparser

android xmlpullparser get need element


this is xml
enter image description here

this is xmlpullparser enter image description here

it will get all img.
but I want get img of phil is phil_1 and phil_2.
I looking anywhere but can't get answer.
Can anybody help me ?
thank for reading. sorry for my bad english


Solution

  • You already have most of what you need. To complete the comparison, all you have to do is:

    // Get the attribute name that you first need
    case XmlPullParser.START_TAG:
        String attr = parser.getAttributeName(null, "phil");
        if(!attr.equals("phil"))
            continue; // continue to the next event type
    
    // So when the code hits this case, you know for sure the attribute type is Phil
    case XmlPullParser.TEXT:
        // Just do your regular stuff here