{"id":324,"date":"2010-11-17T22:39:00","date_gmt":"2010-11-17T22:39:00","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/2012\/10\/boost-your-android-xml-parsing-with-xml-pull.html"},"modified":"2012-10-21T19:21:49","modified_gmt":"2012-10-21T19:21:49","slug":"boost-android-xml-parsing-xml-pull","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2010\/11\/boost-android-xml-parsing-xml-pull.html","title":{"rendered":"Boost your Android XML parsing with XML Pull"},"content":{"rendered":"<p>In today&#8217;s technology world, XML parsing capabilities are a necessity for a big number of applications whether they are mobile, enterprise or in the cloud. Despite the fact that XML is bloated and very verbose, it still remains king in the field of data exchange (JSON is a nice alternative, check our tutorial for <a href=\"http:\/\/www.javacodegeeks.com\/2010\/07\/add-json-gwt-application.html\">JSON integration with GWT<\/a>).<\/p>\n<p>There are two main approaches in XML parsing: SAX and DOM. The <a href=\"http:\/\/en.wikipedia.org\/wiki\/Simple_API_for_XML\">SAX<\/a> specification defines an event-based approach where the implemented parsers scan through XML data and they use call-back handlers whenever certain parts of the document have been reached. On the other hand, the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Document_Object_Model\">DOM<\/a> specification defines a tree-based approach to navigating an XML document.<\/p>\n<p>In a <a href=\"http:\/\/www.javacodegeeks.com\/2010\/10\/android-full-app-part-3-parsing-xml.html\">previous tutorial<\/a> we saw how to parse XML documents using SAX. DOM object is relatively resources intensive and perhaps not suitable for use in a mobile environment. A SAX parser is quite more lightweight and uses a smaller memory footprint. SAX is a push parsing API but the approach it uses is somewhat \u201cbroken\u201d in the sense that, rather than being called by the parsing application, the SAXParser uses a message handler with \u201ccall backs\u201d.<\/p>\n<p>An alternative to that is using a relatively new practice, the \u201cpull parsing\u201d approach. In short, the main difference with this approach is that the user code is in control and can pull more data when it is ready to process it. You can find an excellent article in <a href=\"http:\/\/www.bearcave.com\/software\/java\/xml\/xmlpull.html\">processing XML with the XML Pull Parser<\/a> as well as some <a href=\"http:\/\/www.extreme.indiana.edu\/%7Easlom\/xmlpull\/patterns.html\">XML pull parsing patterns<\/a>.<\/p>\n<p>The Android SDK includes support for XML Pull parsing (which surprisingly is there from Level 1 API) via the <a href=\"http:\/\/developer.android.com\/reference\/org\/xmlpull\/v1\/package-summary.html\">XML Pull package<\/a>. The main class used is the <a href=\"http:\/\/developer.android.com\/reference\/org\/xmlpull\/v1\/XmlPullParser.html\">XmlPullParser<\/a> with the Javadoc page including a simple example of how to use the parser. In this tutorial I am going to show you how to add pull parsing capabilities into your Android application and how to implement a more sophisticated parser than the one provided by the API docs.<\/p>\n<p>If you are a regular <a href=\"http:\/\/www.javacodegeeks.com\/\">JavaCodeGeeks<\/a> reader, you probably know that I have started a tutorial series where I am building a <a href=\"http:\/\/www.javacodegeeks.com\/2010\/10\/android-full-application-tutorial.html\">full application<\/a> from scratch. In its third part (<a href=\"http:\/\/www.javacodegeeks.com\/2010\/10\/android-full-app-part-3-parsing-xml.html\">\u201cAndroid Full App, Part 3: Parsing the XML response\u201d<\/a>), I use an XML based external API in order to perform movies search. A sample XML response is the following:<br \/>\n<a href=\"http:\/\/dl.dropbox.com\/u\/7215751\/JavaCodeGeeks\/AndroidFullAppTutorialPart03\/Transformers+2007.xml\"><br \/>\nMovies search for \u201cTransformers\u201d and (year) \u201c2007\u201d<\/a><\/p>\n<p>In that tutorial I presented the SAX based approach, but know we are going to boost things up by using Android&#8217;s XML pull parser. First, let&#8217;s create a new Android project inside Eclipse. I am calling it \u201cAndroidXmlPullParserProject\u201d. Here is a screenshot of the configuration used:<\/p>\n<p><a href=\"http:\/\/3.bp.blogspot.com\/_piNjpdpJZXA\/TOL79qGwH7I\/AAAAAAAAAMY\/fhtPKdyH1p8\/s1600\/01-xml-pull-new-project.png\"><img decoding=\"async\" alt=\"\" border=\"0\" src=\"http:\/\/3.bp.blogspot.com\/_piNjpdpJZXA\/TOL79qGwH7I\/AAAAAAAAAMY\/fhtPKdyH1p8\/s320\/01-xml-pull-new-project.png\" style=\"cursor: pointer;height: 320px;margin: 0px auto 10px;text-align: center;width: 255px\" \/><\/a><\/p>\n<p>The first step in using the XML Pull API is to obtain a new instance of the XmlPullParserFactory class. This class is used to create implementations of XML Pull Parser defined in XMPULL V1 API. We will disable the namespace awareness of the factory since it is not required by the application&#8217;s needs. Note that this will also improve the parsing speed.<\/p>\n<p>Next, we create a new <a href=\"http:\/\/developer.android.com\/reference\/org\/xmlpull\/v1\/XmlPullParser.html\">XmlPullParser<\/a> by invoking the <a href=\"http:\/\/developer.android.com\/reference\/org\/xmlpull\/v1\/XmlPullParserFactory.html#newPullParser%28%29\">newPullParser<\/a> factory method. An input has to be provided to our parser and that is accomplished via the setInput method, which requires an <a href=\"http:\/\/developer.android.com\/reference\/java\/io\/InputStream.html\">InputStream<\/a> and an encoding as arguments. We provide an input stream obtained by a URL connection (since our XML document is an internet resource), but we do not provide an input encoding (null is just fine).<\/p>\n<p>XML Pull parsing is event-based and in order to parse the whole document, the trick is to create a loop inside which we serially get all the parsing events until we reach the <a href=\"http:\/\/developer.android.com\/reference\/org\/xmlpull\/v1\/XmlPullParser.html#END_DOCUMENT\">END_DOCUMENT<\/a> event. As a showcase example, the code will just print log statements when the following events are encountered:<\/p>\n<ul>\n<li><a href=\"http:\/\/developer.android.com\/reference\/org\/xmlpull\/v1\/XmlPullParser.html#START_TAG\">START_TAG<\/a>: An XML start tag was read.<\/li>\n<li><a href=\"http:\/\/developer.android.com\/reference\/org\/xmlpull\/v1\/XmlPullParser.html#TEXT\">TEXT<\/a>: Text content was read.<\/li>\n<li><a href=\"http:\/\/developer.android.com\/reference\/org\/xmlpull\/v1\/XmlPullParser.html#END_TAG\">END_TAG<\/a>: An XML end tag was read.<\/li>\n<li><a href=\"http:\/\/developer.android.com\/reference\/org\/xmlpull\/v1\/XmlPullParser.html#START_DOCUMENT\">START_DOCUMENT<\/a>: Parser is at the beginning of the document.<\/li>\n<li><a href=\"http:\/\/developer.android.com\/reference\/org\/xmlpull\/v1\/XmlPullParser.html#END_DOCUMENT\">END_DOCUMENT<\/a>: Logical end of the xml document.<\/li>\n<\/ul>\n<p>Here is the source code for our first simple implementation:<\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.android.xml.pull;\r\n\r\nimport java.io.InputStream;\r\nimport java.net.URL;\r\nimport java.net.URLConnection;\r\n\r\nimport org.xmlpull.v1.XmlPullParser;\r\nimport org.xmlpull.v1.XmlPullParserFactory;\r\n\r\nimport android.app.Activity;\r\nimport android.os.Bundle;\r\nimport android.util.Log;\r\n\r\npublic class XmlPullParserActivity extends Activity {\r\n    \r\n    private static final String xmlUrl = \r\n        \"http:\/\/dl.dropbox.com\/u\/7215751\/JavaCodeGeeks\/AndroidFullAppTutorialPart03\/Transformers+2007.xml\";\r\n    \r\n    private final String TAG = getClass().getSimpleName();\r\n    \r\n    @Override\r\n    public void onCreate(Bundle savedInstanceState) {\r\n    \r\n        super.onCreate(savedInstanceState);\r\n        setContentView(R.layout.main);                \r\n\r\n        try {\r\n            parseFromUrl();\r\n        } \r\n        catch (Exception e) {\r\n            Log.e(TAG, \"Error while parsing\", e);\r\n        }\r\n        \r\n    }\r\n    \r\n    private void parseFromUrl() throws Exception {\r\n        \r\n        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();\r\n        factory.setNamespaceAware(false);\r\n        XmlPullParser xpp = factory.newPullParser();\r\n        \r\n        URL url = new URL(xmlUrl);\r\n        URLConnection ucon = url.openConnection();\r\n        InputStream is = ucon.getInputStream();\r\n        \r\n        xpp.setInput(is, null);\r\n        \r\n        int eventType = xpp.getEventType();\r\n        \r\n        while (eventType != XmlPullParser.END_DOCUMENT) {\r\n            \r\n            if (eventType == XmlPullParser.START_DOCUMENT) {\r\n                Log.d(TAG, \"Start document\");\r\n            }\r\n            else if (eventType == XmlPullParser.END_DOCUMENT) {\r\n                Log.d(TAG, \"End document\");\r\n            }\r\n            else if (eventType == XmlPullParser.START_TAG) {\r\n                Log.d(TAG, \"Start tag \" + xpp.getName());\r\n            }\r\n            else if (eventType == XmlPullParser.END_TAG) {\r\n                Log.d(TAG, \"End tag \" + xpp.getName());\r\n            }\r\n            else if (eventType == XmlPullParser.TEXT) {\r\n                Log.d(TAG, \"Text \" + xpp.getText());\r\n            }\r\n            \r\n            eventType = xpp.next();\r\n            \r\n        }\r\n        \r\n    }\r\n<\/pre>\n<p>Include the <a href=\"http:\/\/developer.android.com\/reference\/android\/Manifest.permission.html#INTERNET\">INTERNET<\/a> permission into your Android Manifest file and launch the project. Go to the DDMS view of Eclipse and create a new filter using the class name \u201cXmlPullParserActivity\u201d as shown in the following image:<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><a href=\"http:\/\/4.bp.blogspot.com\/_piNjpdpJZXA\/TOL8yDSzHoI\/AAAAAAAAAMg\/-an6h2uR_rs\/s1600\/02-activity-filter.png\"><img decoding=\"async\" alt=\"\" border=\"0\" src=\"http:\/\/4.bp.blogspot.com\/_piNjpdpJZXA\/TOL8yDSzHoI\/AAAAAAAAAMg\/-an6h2uR_rs\/s320\/02-activity-filter.png\" style=\"cursor: pointer;height: 240px;margin: 0px auto 10px;text-align: center;width: 320px\" \/><\/a><\/p>\n<p>You should then find the various log messages in the LogCat view:<\/p>\n<p><a href=\"http:\/\/3.bp.blogspot.com\/_piNjpdpJZXA\/TOL87KEiBPI\/AAAAAAAAAMo\/T-jtOGk4an8\/s1600\/03-logcat-view.png\"><img decoding=\"async\" alt=\"\" border=\"0\" src=\"http:\/\/3.bp.blogspot.com\/_piNjpdpJZXA\/TOL87KEiBPI\/AAAAAAAAAMo\/T-jtOGk4an8\/s320\/03-logcat-view.png\" style=\"cursor: pointer;height: 111px;margin: 0px auto 10px;text-align: center;width: 320px\" \/><\/a><\/p>\n<p>Notice that no special parsing has occurred. We just got notified when the parser found a new tag, reached the document end etc. However, since we are sure that we have the basic infrastructure ready, we can step it up a bit. First, take a look at the <a href=\"http:\/\/dl.dropbox.com\/u\/7215751\/JavaCodeGeeks\/AndroidFullAppTutorialPart03\/Transformers+2007.xml\">sample XML<\/a> (provided by the <a href=\"http:\/\/api.themoviedb.org\/2.1\">TMDb API<\/a>):<\/p>\n<p><a href=\"http:\/\/3.bp.blogspot.com\/_piNjpdpJZXA\/TOL9GuXIWmI\/AAAAAAAAAMw\/IMrVyTyq7Jg\/s1600\/04-xml-view.png\"><img decoding=\"async\" alt=\"\" border=\"0\" src=\"http:\/\/3.bp.blogspot.com\/_piNjpdpJZXA\/TOL9GuXIWmI\/AAAAAAAAAMw\/IMrVyTyq7Jg\/s320\/04-xml-view.png\" style=\"cursor: pointer;height: 238px;margin: 0px auto 10px;text-align: center;width: 320px\" \/><\/a><\/p>\n<p>It is your typical XML document with nested elements etc. The data that are interesting to us are those inside the \u201cmovies\u201d element. We will create a Movie class and map each child element to the corresponding class field. Moreover, we will also create an Image class using the same approach. Note that a Movie can have zero or more Images. Thus, the two domain model classes are:<\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.android.xml.pull.model;\r\n\r\nimport java.util.ArrayList;\r\n\r\npublic class Movie {\r\n    \r\n    public String score;\r\n    public String popularity;\r\n    public boolean translated;\r\n    public boolean adult;\r\n    public String language;\r\n    public String originalName;\r\n    public String name;\r\n    public String type;\r\n    public String id;\r\n    public String imdbId;\r\n    public String url;\r\n    public String votes;\r\n    public String rating;\r\n    public String certification;\r\n    public String overview;\r\n    public String released;\r\n    public String version;\r\n    public String lastModifiedAt;\r\n    public ArrayList&lt;Image&gt; imagesList;\r\n\r\n}\r\n<\/pre>\n<pre class=\"brush:java\">package com.javacodegeeks.android.xml.pull.model;\r\n\r\npublic class Image {\r\n    \r\n    public String type;\r\n    public String url;\r\n    public String size;\r\n    public int width;\r\n    public int height;\r\n\r\n}\r\n\r\n<\/pre>\n<p>We are now ready to start the parsing. We first create the factory and the pull parser the same way as before. Note that the document does not directly start with the \u201cmovies\u201d element, but there are a few elements that we wish to skip. That is accomplished by using the methods <a href=\"http:\/\/developer.android.com\/reference\/org\/xmlpull\/v1\/XmlPullParser.html#nextTag%28%29\">nextTag<\/a> (for <a href=\"http:\/\/developer.android.com\/reference\/org\/xmlpull\/v1\/XmlPullParser.html#START_TAG\">START_TAG<\/a> and <a href=\"http:\/\/developer.android.com\/reference\/org\/xmlpull\/v1\/XmlPullParser.html#END_TAG\">END_TAG<\/a> events) and <a href=\"http:\/\/developer.android.com\/reference\/org\/xmlpull\/v1\/XmlPullParser.html#nextText%28%29\">nextText<\/a> (for <a href=\"http:\/\/developer.android.com\/reference\/org\/xmlpull\/v1\/XmlPullParser.html#TEXT\">TEXT<\/a> events). <\/p>\n<p>Now we are ready to proceed with the interesting parsing. We are going to use a \u201crecursion-like\u201d approach. The \u201cmovies\u201d element contains a number of \u201cmovie\u201d elements where a \u201cmovie\u201d element contains a number of \u201cimage\u201d elements. Thus, we \u201cdrill-down\u201d from the parent elements to the child ones using a dedicated method for the parsing of each element. From one method to an other, we pass the <a href=\"http:\/\/developer.android.com\/reference\/org\/xmlpull\/v1\/XmlPullParser.html\">XmlPullParser<\/a> instance as argument since there is a unique parser implementing the parsing. The result of each method is an instance of the model class and finally a list of movies. In order to check the name of the current element, we use the <a href=\"http:\/\/developer.android.com\/reference\/org\/xmlpull\/v1\/XmlPullParser.html#getName%28%29\">getName<\/a> method and in order to retrieve the enclosed text we use the <a href=\"http:\/\/developer.android.com\/reference\/org\/xmlpull\/v1\/XmlPullParser.html#nextText%28%29\">nextText<\/a> method. For attributes, we use the <a href=\"http:\/\/developer.android.com\/reference\/org\/xmlpull\/v1\/XmlPullParser.html#getAttributeValue%28java.lang.String,%20java.lang.String%29\">getAttributeValue<\/a> method where the first argument is the namespace (null in our case) and the second is the attribute name.<\/p>\n<p>Enough talking, let&#8217;s see how all these are translated to code:<\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.android.xml.pull;\r\n\r\nimport java.io.IOException;\r\nimport java.io.InputStream;\r\nimport java.net.URL;\r\nimport java.net.URLConnection;\r\nimport java.util.ArrayList;\r\nimport java.util.LinkedList;\r\nimport java.util.List;\r\n\r\nimport org.xmlpull.v1.XmlPullParser;\r\nimport org.xmlpull.v1.XmlPullParserException;\r\nimport org.xmlpull.v1.XmlPullParserFactory;\r\n\r\nimport android.app.Activity;\r\nimport android.os.Bundle;\r\nimport android.util.Log;\r\n\r\nimport com.javacodegeeks.android.xml.pull.model.Image;\r\nimport com.javacodegeeks.android.xml.pull.model.Movie;\r\n\r\npublic class XmlPullParserActivity extends Activity {\r\n    \r\n    private static final String xmlUrl = \r\n        \"http:\/\/dl.dropbox.com\/u\/7215751\/JavaCodeGeeks\/AndroidFullAppTutorialPart03\/Transformers+2007.xml\";\r\n    \r\n    private final String TAG = getClass().getSimpleName();\r\n    \r\n    @Override\r\n    public void onCreate(Bundle savedInstanceState) {\r\n        \r\n        super.onCreate(savedInstanceState);\r\n        setContentView(R.layout.main);                \r\n\r\n        try {\r\n            List&lt;Movie&gt; movies = parseFromUrl();\r\n            for (Movie movie : movies) {\r\n                Log.d(TAG, \"Movie:\"+movie);\r\n            }\r\n        } \r\n        catch (Exception e) {\r\n            Log.e(TAG, \"Error while parsing\", e);\r\n        }\r\n        \r\n    }\r\n    \r\n    private List&lt;Movie&gt; parseFromUrl() throws XmlPullParserException, IOException {\r\n        \r\n        List&lt;Movie&gt; moviesList = null;\r\n        \r\n        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();\r\n        factory.setNamespaceAware(false);\r\n        XmlPullParser parser = factory.newPullParser();\r\n        \r\n        URL url = new URL(xmlUrl);\r\n        URLConnection ucon = url.openConnection();\r\n        InputStream is = ucon.getInputStream();\r\n        \r\n        parser.setInput(is, null);\r\n        \r\n        parser.nextTag();        \r\n        parser.nextTag();        \r\n        parser.nextTag();        \r\n        parser.nextTag();        \r\n        parser.nextText();        \r\n        parser.nextTag();\r\n                \r\n        moviesList = parseMovies(parser);\r\n        \r\n        return moviesList;\r\n        \r\n    }\r\n    \r\n    private List&lt;Movie&gt; parseMovies(XmlPullParser parser) throws XmlPullParserException, IOException {\r\n        \r\n        List&lt;Movie&gt; moviesList = new LinkedList&lt;Movie&gt;();\r\n        \r\n        Log.d(TAG, \"parseMovies tag \" + parser.getName());\r\n\r\n        while (parser.nextTag() == XmlPullParser.START_TAG) {\r\n            Log.d(TAG, \"parsing movie\");\r\n            Movie movie = parseMovie(parser);\r\n            moviesList.add(movie);\r\n        }\r\n        \r\n        return moviesList;\r\n        \r\n    }\r\n    \r\n    private Movie parseMovie(XmlPullParser parser) throws XmlPullParserException, IOException {\r\n        \r\n        Movie movie = new Movie();\r\n        Log.d(TAG, \"parseMovie tag \" + parser.getName());\r\n        \r\n        while (parser.nextTag() == XmlPullParser.START_TAG) {\r\n            \r\n            if (parser.getName().equals(\"name\")) {\r\n                movie.name = parser.nextText();\r\n            } \r\n            else if (parser.getName().equals(\"score\")) {\r\n                movie.score = parser.nextText();\r\n            }\r\n            else if (parser.getName().equals(\"images\")) {\r\n                Image image = parseImage(parser);\r\n                movie.imagesList = new ArrayList&lt;Image&gt;();\r\n                movie.imagesList.add(image);\r\n            }\r\n            else if (parser.getName().equals(\"version\")) {\r\n                movie.version = parser.nextText();\r\n            }\r\n            else {\r\n                parser.nextText();\r\n            }\r\n            \r\n        }\r\n        \r\n        return movie;\r\n        \r\n    }\r\n    \r\n    private Image parseImage(XmlPullParser parser) throws XmlPullParserException, IOException {\r\n        \r\n        Image image = new Image();\r\n        Log.d(TAG, \"parseImage tag \" + parser.getName());\r\n        \r\n        while (parser.nextTag() == XmlPullParser.START_TAG) {\r\n            \r\n            if (parser.getName().equals(\"image\")) {\r\n                image.type = parser.getAttributeValue(null, \"type\");\r\n                image.url = parser.getAttributeValue(null, \"url\");\r\n                image.size = parser.getAttributeValue(null, \"size\");\r\n                image.width = Integer.parseInt(parser.getAttributeValue(null, \"width\"));\r\n                image.height = Integer.parseInt(parser.getAttributeValue(null, \"height\"));\r\n            }\r\n            parser.next();\r\n            \r\n        }\r\n        \r\n        return image;\r\n        \r\n    }\r\n    \r\n}\r\n<\/pre>\n<p>The code is pretty straightforward, just remember that we are using a \u201cdrill-down\u201d approach in order to parse the deeper element (Movies ? Movie ? Images). Please note that in the Movie parsing method we included only some of the fields for brevity reasons. Also, do not forget to invoke the parser.nextText() method in order to allow the parser to move and fetch the next tag (else  you will get some nasty exceptions since the current event will not be of type <a href=\"http:\/\/developer.android.com\/reference\/org\/xmlpull\/v1\/XmlPullParser.html#START_TAG\">START_TAG<\/a>).<\/p>\n<p>Run the project&#8217;s configuration again and check that the LogCat contains the correct debugging statements:<\/p>\n<p><a href=\"http:\/\/3.bp.blogspot.com\/_piNjpdpJZXA\/TOL995Wf1wI\/AAAAAAAAAM4\/1g3_9-FPSms\/s1600\/05-logcat-adv-view.png\"><img decoding=\"async\" alt=\"\" border=\"0\" src=\"http:\/\/3.bp.blogspot.com\/_piNjpdpJZXA\/TOL995Wf1wI\/AAAAAAAAAM4\/1g3_9-FPSms\/s320\/05-logcat-adv-view.png\" style=\"cursor: pointer;height: 103px;margin: 0px auto 10px;text-align: center;width: 320px\" \/><\/a><\/p>\n<p>That&#8217;s it! XML Pull parsing capabilities straight to your Android application. You can download the Eclipse project created for this article <a href=\"http:\/\/dl.dropbox.com\/u\/7215751\/JavaCodeGeeks\/AndroidXmlPullParsingTutorial\/AndroidXmlPullParserProject.zip\">here<\/a>.<\/p>\n<div style=\"margin-bottom: 0px;margin-left: 0px;margin-right: 0px;margin-top: 0px\"><strong><i>Related Articles :<\/i><\/strong><\/div>\n<ul>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2010\/10\/android-full-application-tutorial.html\">\u201cAndroid Full Application Tutorial\u201d series<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2010\/09\/android-text-to-speech-application.html\">Android Text-To-Speech Application<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2010\/09\/android-reverse-geocoding-yahoo-api.html\">Android Reverse Geocoding with Yahoo API &#8211; PlaceFinder<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2010\/09\/android-location-based-services.html\">Android Location Based Services Application \u2013 GPS location<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2010\/06\/embracing-android-awesomeness-quick.html\">Install Android OS on your PC with VirtualBox<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2010\/06\/embracing-android-awesomeness-quick.html\">Embracing the Android awesomeness: A quick overview<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In today&#8217;s technology world, XML parsing capabilities are a necessity for a big number of applications whether they are mobile, enterprise or in the cloud. Despite the fact that XML is bloated and very verbose, it still remains king in the field of data exchange (JSON is a nice alternative, check our tutorial for JSON &hellip;<\/p>\n","protected":false},"author":3,"featured_media":46,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[83,107,108],"class_list":["post-324","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-android-core","tag-android-tutorial","tag-xml","tag-xmlpull"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Boost your Android XML parsing with XML Pull - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In today&#039;s technology world, XML parsing capabilities are a necessity for a big number of applications whether they are mobile, enterprise or in the\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2010\/11\/boost-android-xml-parsing-xml-pull.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Boost your Android XML parsing with XML Pull - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In today&#039;s technology world, XML parsing capabilities are a necessity for a big number of applications whether they are mobile, enterprise or in the\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2010\/11\/boost-android-xml-parsing-xml-pull.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2010-11-17T22:39:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-10-21T19:21:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/android-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Ilias Tsagklis\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ilias Tsagklis\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2010\\\/11\\\/boost-android-xml-parsing-xml-pull.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2010\\\/11\\\/boost-android-xml-parsing-xml-pull.html\"},\"author\":{\"name\":\"Ilias Tsagklis\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/9a83496b285d30c61e8a674625c1350e\"},\"headline\":\"Boost your Android XML parsing with XML Pull\",\"datePublished\":\"2010-11-17T22:39:00+00:00\",\"dateModified\":\"2012-10-21T19:21:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2010\\\/11\\\/boost-android-xml-parsing-xml-pull.html\"},\"wordCount\":1247,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2010\\\/11\\\/boost-android-xml-parsing-xml-pull.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/android-logo.jpg\",\"keywords\":[\"Android Tutorial\",\"XML\",\"XMLPull\"],\"articleSection\":[\"Android Core\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2010\\\/11\\\/boost-android-xml-parsing-xml-pull.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2010\\\/11\\\/boost-android-xml-parsing-xml-pull.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2010\\\/11\\\/boost-android-xml-parsing-xml-pull.html\",\"name\":\"Boost your Android XML parsing with XML Pull - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2010\\\/11\\\/boost-android-xml-parsing-xml-pull.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2010\\\/11\\\/boost-android-xml-parsing-xml-pull.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/android-logo.jpg\",\"datePublished\":\"2010-11-17T22:39:00+00:00\",\"dateModified\":\"2012-10-21T19:21:49+00:00\",\"description\":\"In today's technology world, XML parsing capabilities are a necessity for a big number of applications whether they are mobile, enterprise or in the\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2010\\\/11\\\/boost-android-xml-parsing-xml-pull.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2010\\\/11\\\/boost-android-xml-parsing-xml-pull.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2010\\\/11\\\/boost-android-xml-parsing-xml-pull.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/android-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/android-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2010\\\/11\\\/boost-android-xml-parsing-xml-pull.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Android\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/android\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Android Core\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/android\\\/android-core\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Boost your Android XML parsing with XML Pull\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/9a83496b285d30c61e8a674625c1350e\",\"name\":\"Ilias Tsagklis\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/43505f28bb49f6e290c24be0b209ccc1af350f0f6587025ffd4847ef44bf6b78?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/43505f28bb49f6e290c24be0b209ccc1af350f0f6587025ffd4847ef44bf6b78?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/43505f28bb49f6e290c24be0b209ccc1af350f0f6587025ffd4847ef44bf6b78?s=96&d=mm&r=g\",\"caption\":\"Ilias Tsagklis\"},\"description\":\"Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.\",\"sameAs\":[\"http:\\\/\\\/www.iliastsagklis.com\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/iliastsagklis\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/ilias-tsagklis\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Boost your Android XML parsing with XML Pull - Java Code Geeks","description":"In today's technology world, XML parsing capabilities are a necessity for a big number of applications whether they are mobile, enterprise or in the","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2010\/11\/boost-android-xml-parsing-xml-pull.html","og_locale":"en_US","og_type":"article","og_title":"Boost your Android XML parsing with XML Pull - Java Code Geeks","og_description":"In today's technology world, XML parsing capabilities are a necessity for a big number of applications whether they are mobile, enterprise or in the","og_url":"https:\/\/www.javacodegeeks.com\/2010\/11\/boost-android-xml-parsing-xml-pull.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2010-11-17T22:39:00+00:00","article_modified_time":"2012-10-21T19:21:49+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/android-logo.jpg","type":"image\/jpeg"}],"author":"Ilias Tsagklis","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Ilias Tsagklis","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2010\/11\/boost-android-xml-parsing-xml-pull.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2010\/11\/boost-android-xml-parsing-xml-pull.html"},"author":{"name":"Ilias Tsagklis","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/9a83496b285d30c61e8a674625c1350e"},"headline":"Boost your Android XML parsing with XML Pull","datePublished":"2010-11-17T22:39:00+00:00","dateModified":"2012-10-21T19:21:49+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2010\/11\/boost-android-xml-parsing-xml-pull.html"},"wordCount":1247,"commentCount":2,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2010\/11\/boost-android-xml-parsing-xml-pull.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/android-logo.jpg","keywords":["Android Tutorial","XML","XMLPull"],"articleSection":["Android Core"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2010\/11\/boost-android-xml-parsing-xml-pull.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2010\/11\/boost-android-xml-parsing-xml-pull.html","url":"https:\/\/www.javacodegeeks.com\/2010\/11\/boost-android-xml-parsing-xml-pull.html","name":"Boost your Android XML parsing with XML Pull - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2010\/11\/boost-android-xml-parsing-xml-pull.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2010\/11\/boost-android-xml-parsing-xml-pull.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/android-logo.jpg","datePublished":"2010-11-17T22:39:00+00:00","dateModified":"2012-10-21T19:21:49+00:00","description":"In today's technology world, XML parsing capabilities are a necessity for a big number of applications whether they are mobile, enterprise or in the","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2010\/11\/boost-android-xml-parsing-xml-pull.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2010\/11\/boost-android-xml-parsing-xml-pull.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2010\/11\/boost-android-xml-parsing-xml-pull.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/android-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/android-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2010\/11\/boost-android-xml-parsing-xml-pull.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Android","item":"https:\/\/www.javacodegeeks.com\/category\/android"},{"@type":"ListItem","position":3,"name":"Android Core","item":"https:\/\/www.javacodegeeks.com\/category\/android\/android-core"},{"@type":"ListItem","position":4,"name":"Boost your Android XML parsing with XML Pull"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/9a83496b285d30c61e8a674625c1350e","name":"Ilias Tsagklis","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/43505f28bb49f6e290c24be0b209ccc1af350f0f6587025ffd4847ef44bf6b78?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/43505f28bb49f6e290c24be0b209ccc1af350f0f6587025ffd4847ef44bf6b78?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/43505f28bb49f6e290c24be0b209ccc1af350f0f6587025ffd4847ef44bf6b78?s=96&d=mm&r=g","caption":"Ilias Tsagklis"},"description":"Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.","sameAs":["http:\/\/www.iliastsagklis.com\/","https:\/\/www.linkedin.com\/in\/iliastsagklis"],"url":"https:\/\/www.javacodegeeks.com\/author\/ilias-tsagklis"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/324","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=324"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/324\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/46"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=324"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=324"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=324"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}