Created
September 7, 2011 16:08
-
-
Save rsaunders100/1200984 to your computer and use it in GitHub Desktop.
(Android) An simple example use of a XML pull parser.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String parseInputStream(InputStream inputStream) throws Exception | |
{ | |
XmlPullParser parser = Xml.newPullParser(); | |
parser.setInput(inputStream, null); | |
int eventType = parser.getEventType(); | |
while (eventType != XmlPullParser.END_DOCUMENT) { | |
switch (eventType){ | |
case XmlPullParser.START_DOCUMENT: | |
break; | |
case XmlPullParser.START_TAG: | |
String tagName = parser.getName(); | |
if (tagName.equalsIgnoreCase("status")) | |
{ | |
String statusText = parser.nextText(); | |
return statusText; | |
} | |
} | |
eventType = parser.next(); | |
} | |
// No status tag found so throw an exception | |
throw new RuntimeException("No Status tag found in XML document"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment