문제

This question already has an answer here:

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...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top