I am trying to parse XML. I also used FileInputStream for my XML file. I put the XML file in the Android resources folder, the META-INF folder. This is the name of the file "container.XML".
Here is my parseXML code,
public void parseXMLinfoBook() throws FileNotFoundException, ParserConfigurationException, SAXException{
FileInputStream in = new FileInputStream("file:///android_asset/META-INF/container.xml");
StringBuffer inLine = new StringBuffer();
InputStreamReader isr = new InputStreamReader(in);
BufferedReader inRd = new BufferedReader(isr);
SAXParserFactory spf=SAXParserFactory.newInstance();
SAXParser spr=spf.newSAXParser();
XMLReader xmlreader = spr.getXMLReader();
XmlHandler xmlhe=new XmlHandler();
xmlreader.setContentHandler(xmlhe);
}
Here is the Button.SetonClick code,
public void onClick(View v) {
try {
parseXMLinfoBook();
} catch (FileNotFoundException e) {
e.printStackTrace();
tv.setText("ErrorPath "+e.getMessage());
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
}
}
});
I only got an error message. Hope to help!
source
share