Parse XML in Android(tm) with xml-drafts-framework
Xml-drafts-framework is a small framework to parse XML based on XML-pull-parser for Android. This framework is written by me and open-sourced under apache license on github. It aims to work with XML and to write less code as possible.
-
you need an xml:
<root>
<item name="test-name" />
</root> -
set up your parser-states:
enum States implements Tag { ITEM( "item "), ROOT( "root", ITEM) ...
}
-
write a parser based on states
final XMLTagHandler tagHandler = new XMLTagHandler(States.ROOT, callback) { @Override protected void startTag(final Tag current, final XMLTagFacade facade) throws Exception { if( current == States.ITEM ) { System.out.println( "-- found an item: " + facade.getAttribute("name" )); } } @Override protected void closeTag(Tag current) throws Exception { ; } };
-
run a parser
final InpuStream in = ...; final XMLParserLoop loop = XMLParserLoop.create( tagHandler ); loop.useInput( in ); loop.run();
with greetings from Cologne,
Andreas Siebert, ask@touchableheroes.com
(aka DrDrej)
Written by Andreas Siebert
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Android
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#