开发者

To parse an xml file [duplicate]

This question already has answers here: How to draw a path on a map using kml file? (4开发者_Python百科 answers) Closed 7 years ago.

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜