Previously in my Android project I passed a URL String (Web Address) to the XMLReader to parse. But now I want to pass the XML File from my the project itself for this purpose.
- Where should I place the XML File (Note:- After installing it on a device, I expect to update the contents of the XML File weekly. Placement of the XML File should be flexible for this)
- How can I retrieve data from the XML File to the
XMLReader
Previous (Working)
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
URL sourceUrl;
sourceUrl = new URL(
"http://www.androidpeople.com/wp-content/uploads/2010/06/example.xml");
XMLHandler myXMLHandler = new XMLHandler();
xr.setContentHandler(myXMLHandler);
xr.parse(new InputSource(sourceUrl.openStream()));
To answer your second question, you can construct an
InputSourcefrom aFileInputStream, similar to what you are doing with the url. I suggest to also set the systemId to get nicer error reporting and in case you need to resolve relative paths from the xml.