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

How to design a motherboard for your electronics project - Part 1 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.
Categories:  Projects
Posted: February 21, 2021
Caffstat Beta Caffstat is the first Hackable Home Thermostat
Categories:  Projects
Posted: February 20, 2021
v2 Updates to my HomeKit Thermostat Making my thermostat project into something I can actually use every day
Categories:  Projects
Posted: December 31, 2020
Building my own HomeKit Thermostat Holiday 2020 project, building a custom HomeKit enabled thermostat
Categories:  Projects
Posted: December 27, 2020
Unwritten Coding Standards: Vertical Whitespace Simple vertical whitespace rules that will make any code easier to read
Categories:  Coding, mike8
Posted: May 27, 2020