Click anywhere to close

XmlParser for Android

XmlParser is an XmlParser that utilizes XmlPullParser to read in a generic Xml stream and create a composite XmlObject. This object contains all of the data that was in the xml file. The intention of this library is to simplify any code that used to have to write a bunch of boiler plate code in order to interact with XmlPullParser. Below are some usage examples of XmlParser.

Sample Xml File:
<array>
    <item>First Item</item>
    <anotheritem>Second Item</anotheritem>
</array>

Java code snippet:
InputStream is = getContext().getResources().openRawFile( R.raw.simple_xml )
XmlParser parser = new XmlParser( is, null );
try {
    XmlObject obj = parser.getXmlObject();
    Log.v( "Xml Parser", "Array with name: " + child.getTagName() );
    for( XmlObject child : obj.getChildren() ) {
        Log.v( "Xml Parser", "Child Tag Name: " + child.getTagName() +
                                     " Value: " + child.getValue() );
    }
} catch ( XmlParserException e ) {
    e.printStackTrace(); // Something went wrong.  Xml is formated incorrectly
}

Expected logcat output:
Array with name: array
Child Tag Name: item Value: First Item
Child Tag Name: anotheritem Value: Second Item


Recent Other Posts

Google Cache Javascript Shortcut Automatically takes you to the lastest google cached version of a site
Categories:  Web
Posted: June 12, 2017
I hate writing web scrapers Proposition for a better way to scrape`
Categories:  Projects, Web, Scraping
Posted: April 02, 2016
One-to-Many Relationships in CouchDB How to best create One-to-Many relationships in CouchDB
Categories:  Web, CouchDB
Posted: July 09, 2014
ReddPics Javascript Shortcut Automatically takes you from reddit to reddpics
Categories:  Web
Posted: June 03, 2014
JP Morgan Code For Good 2013 Jawbone UP data based donation page
Categories:  Python, Web
Posted: May 29, 2014