Give me an example on how to parse a custom xml file using DOM
A:
For reference here is an excellent article on this by Michael Galpin: Working with XML on Android.
Michael shows several ways to parse and create XML with Android. There are several ways to do SAX parsing included.
To quote from his article, using the simplified android.util.Xml class, here is an example (note that you must implement the handler, see the article for details):
public class AndroidSaxFeedParser extends BaseFeedParser {
public AndroidSaxFeedParser(String feedUrl) {
super(feedUrl);
}
public List<Message> parse() {
RssHandler handler = new RssHandler();
try {
Xml.parse(this.getInputStream(), Xml.Encoding.UTF_8, handler);
} catch (Exception e) {
throw new RuntimeException(e);
}
return handler.getMessages();
}
}
Charlie Collins
2010-06-30 14:51:01