I created an XML parser on Android for XML data that was in a byte array as follows:
Create a class that extends DefaultHandler.
Create a method in this class similar to the following:
public void ParseXMLByteArray(byte[] xmlData, int len)
{
SAXParserFactory spf = SAXParserFactory.newInstance();
try
{
// Create a SAX parser
SAXParser mySP = spf.newSAXParser();
// Get an XML reader from the parser
XMLReader myXR = mySP.getXMLReader();
// Tell the reader this class will supply content callbacks
myXR.setContentHandler(this);
// Kick off the parse operation
// You will get ContentHandler callbacks via DefaultHandler overrides
myXR.parse(new InputSource(new ByteArrayInputStream(xmlData, 0, len)));
}
catch ( Exception excp )
{
// Handle exceptions
}
}
You would of course want to make the input source your local file. Your DefaultHandler overrides would process the elements and add them to your database.