Search code examples
androidxmlxmlpullparser

Android XmlPullParser get value between tags


I have something like this in XML:

<trkpt lat="-32.577000" lon="-71.443764">
            <ele>2.204529</ele>
            <time>2015-12-27T12:35:45Z</time>

I can get lat and lon with

XmlPullParser parser = factory.newPullParser(); parser.getAttributeValue(0); parser.getAttributeValue(1);

But how can I get the value stored between the "ele" tag?


Solution

  • you have to use getText() on the current element. From the documentation

    Returns the text content of the current event as String.
    

    Of course you have to move the parser to the correct element calling next (). From the documentation:

    Get next parsing event