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

Shirtbot It's a slack bot that makes shirts
Posted: August 01, 2021
I feel stuck in the the engineering for engineers trap If you aren't an engineer please read this and reach out, I'd love to chat
Posted: June 20, 2021
Unwritten Coding Standards: Function Ordering A standard for how you should order functions in files to increase the consistency of your code bases
Posted: May 15, 2021
Designing a guitar with hot-swappable pickups I made a custom guitar with hot-swappable pickups
Posted: May 02, 2021
How to design a motherboard for your electronics project - Part 2 Designing a motherboard for your project is a great second step when developing an electronics project. This is the guide I wish existed when I got started doing this.
Posted: April 25, 2021