Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes SAX parser is the solution and here is the basic code to get you started:</p> <pre><code>void parseExampleFunction(){ SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); File myFile = new File( //the XML file which you need to parse ); myFile.createNewFile(); FileInputStream fOut = new FileInputStream(myFile); BufferedInputStream bos = new BufferedInputStream( fOut ); /** Create handler to handle XML Tags ( extends DefaultHandler ) */ MessagesXMLHandler myXMLHandler = new MessagesXMLHandler(context); xr.setContentHandler(myXMLHandler); xr.parse(new InputSource(bos)); } // the class where the parsing logic needs to defined.This preferably can be in a different .java file public class MessagesXMLHandler extends DefaultHandler{ //this function is called automatically when a start tag is encountered @Override public void startElement(String uri, String localName, String qName,Attributes attributes) throws SAXException //variable localName is the name of the tag //this function is called autiomatically when an end tag is encountered @Override public void endElement(String uri, String localName, String qName) throws SAXException { } //this function gets called to return the value stored betweeen the closing and opening tags @Override public void characters(char[] ch, int start, int length) throws SAXException { //now variable value has the value stored between the closing and opening tags String value=new String(ch,start,length); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload