I have an XML file in the drawable-folder. I want parse the XML-file using XML-parsing(sax parsing).
I used following code for that:
private void getDataFromFile(int mntFile) throws SAXException, IOException {
// TODO Auto-generated method stub
SAXParserFactory factory = SAXParserFactory.newInstance();
System.out.println("in method");
try {
saxParser = factory.newSAXParser();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
DefaultHandler handler = new DefaultHandler() {
boolean id = false;
boolean name = false;
boolean dep = false;
public void startElement(String uri, String localName,String qName,
Attributes attributes) throws SAXException {
//System.out.println("in start");
if (localName.equals("DOCTORID")) {
id = true;
}
if (localName.equals("NAME")) {
name = true;
}
if (localName.equals("DEAPRTMENT")) {
dep = true;
}
}
public void endElement(String uri, String localName,
String qName) throws SAXException {
}
public void characters(char ch[], int start, int length) throws SAXException {
if (id) {
id = false;
}
if (name) {
System.out.println("Name : " + new String(ch, start, length));
mArryLstDoctorNames.add(new String(ch, start, length));
Log.d("doctor","---"+mArryLstDoctorNames);
name = false;
}
if (dep) {
dep = false;
}
}
};
saxParser.parse(R.drawable.myxml, handler);
}
But here saxParser.parse(R.drawable.myxml, handler);
is showing compilation error.
It is the same code working for XML-files, which are on sdcard.