Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse XML string using SAX

Is there any way to parse an XML string using Android SAX?

like image 993
Rui Gonçalves Avatar asked Dec 04 '09 23:12

Rui Gonçalves


People also ask

How an XML Document is parsed using SAX?

This interface requires a number of methods that the SAX parser invokes in response to various parsing events. The major event-handling methods are: startDocument, endDocument, startElement, and endElement. The easiest way to implement this interface is to extend the DefaultHandler class, defined in the org. xml.

Which method does SAX use for processing XML documents?

SAX. The Simple API for XML (SAX) is an event-based API that uses callback routines or event handlers to process different parts of an XML documents. To use SAX, one needs to register handlers for different events and then parse the document.


1 Answers

Yes, first define a SAX ContentHandler:

class MyXmlContentHandler extends DefaultHandler {
   ... // implement SAX callbacks here
}

then you can use the Xml utility class:

Xml.parse(xmlString, new MyXmlContentHandler());
like image 97
Matthias Avatar answered Nov 05 '22 15:11

Matthias