Snippet: XML-Pull-Parser with XPP3

December 28th, 2012 by

When there is XML to be parsed sometimes we’re chosing a DOM parser, sometimes a SAX parser and sometimes we’re using an XML pull parser, especially on Android.

The following short snippet shows how to use the xpp3 xml pull parse to fetch some information in xml format from a public issue tracker and to extract issue details.


Adding Dependencies

Just one dependency needed here: xpp3


Simply use the following build.sbt

name := "xml-pull-parser"
version := "0.0.1"
organization := "com.hascode.tutorial"
libraryDependencies += "xpp3" % "xpp3" % "1.1.4c"


If you’re in Maven, the following pom.xml should match your needs

<project xmlns=""

Fetching, Parsing, Output..

We’re using Atlassian’s public Jira/Issue tracker at to fetch some xml and we’re extracting title and link for each issue …

package com.hascode.tutorial;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
public class ParserExample {
	private static final String urlString = "";
	private static final String ITEM_TITLE = "title";
	private static final String ITEM_LINK = "link";
	public static void main(final String[] args) throws XmlPullParserException,
			MalformedURLException, IOException {
		XmlPullParser xpp = XmlPullParserFactory.newInstance().newPullParser();
		URL url = new URL(urlString);
		BufferedReader in = new BufferedReader(new InputStreamReader(
		try {
			while (xpp.getEventType() != XmlPullParser.END_DOCUMENT) {;
				if (ITEM_TITLE.equals(xpp.getName())) {
					System.out.print("Issue: " + xpp.nextText());
				if (ITEM_LINK.equals(xpp.getName())) {
					System.out.print(" at " + xpp.nextText() + "\n");
		} finally {

Running the code should produce the following output..

$ sbt run
[info] Loading global plugins from /somepath/.sbt/plugins
[info] Set current project to xml-pull-parser (in build file:/data/project/xmlpullparser-example/)
[info] Running com.hascode.tutorial.ParserExample
Issue: [WBS-32] Filter Results do not scroll when exceeding visible screen height at
Issue: [WBS-29] Tarea de prueba at
Issue: [WBS-28] asdsa at
Issue: [WBS-27] Twitter Feed Broken at
Issue: [WBS-26] Stacktrace shown in logs after view the wallboard at
Issue: [WBS-25] No Wallboard gadget for Rapid board burndown at
Issue: [WBS-24] Installing GreenHopper into JIRA after Wallboards causes wallboard to go down until the next restart. at
Issue: [WBS-23] Warnings from Wallboard plugin when starting up Jira at
Issue: [WBS-22] Wallboards broken against JIRA 5.1 EAP at
Issue: [WBS-19] Wallboars fails to start jira 5.0.2 at
Issue: [WBS-18] another wallboard showing in background at
[success] Total time: 6 s, completed Dec 28, 2012 8:57:37 AM

Tutorial Sources

Please feel free to take a look at the sources on my Bitbucket repository or if you’ve got git installed just check it out by using:

git clone


Tags: , , , , , ,

Leave a Reply

Please leave these two fields as-is:

Protected by Invisible Defender. Showed 403 to 113,220 bad guys.