Give me an example on how to parse a custom xml file using DOM
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();
}
}
I remember when i started XML parsing using SAX, i used this link. Download the source code of the Android Essential Book... The "Chapter 5" in the source code deals with XML parsing... hope this helps... It has been done in very simple and elegant manner...
See the sample here:
How to draw a path on a map using kml file?
精彩评论