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 Posts

Farewell to Arkansas St a farewell letter to the best apartment I have ever had
Personal
posted: July 01, 2024
A quick teardown of the NES Zapper Lightgun A quick teardown of the NES Zapper Lightgun, mostly as a love letter to the geniuses who built this and a girl I will always love
Technology
posted: April 26, 2024
shouldibreaknocontact.com I have too much money, and I like to buy novelty domains
Personal
posted: March 28, 2024
How to add Currently Playing to your homepage A code snippet to add a last.fm based currently playing section to your personal site
Technology
posted: February 05, 2024
rough draft 1: is it possible to start anywhere that isn’t the beginning? essay 1 - should we even get started?
Technology
posted: February 02, 2024