Parsing Local Xml File In Android
Hii every one, am brand new to android,i have a doubt can any one help me In this following link http://www.androidpeople.com/android-xml-parsing-tutorial-using-saxparser/ there i
Solution 1:
This is what I did,
InputStream is = res.openRawResource(R.raw.fileName);
xr.parse(new InputSource(is));
Solution 2:
In the link you provided, replace the line 47
xr.parse(newInputSource(sourceUrl.openStream()));
with
xr.parse(getResources().getAssets().open(fileName));
and place your xml file in /res/raw folder
links: Asset Manager Docs and Resources Manager Docs
Solution 3:
try {
// InputStream is = getResources().getAssets().open("yourfilename.xml");InputStreamis=getAssets().open("yourfilename.xml");
SAXParserFactoryspf= SAXParserFactory.newInstance();
SAXParsersp= spf.newSAXParser();
XMLReaderxr= sp.getXMLReader();
MyXMLHandlermyXMLHandler=newMyXMLHandler();
xr.setContentHandler(myXMLHandler);
xr.parse(newInputSource(is));
} catch (Exception e) {
System.out.println("XML Pasing Excpetion = " + e);
}
Solution 4:
In Android you can store data in the assets folder, which can be entered by your code. To address your file use
file:///android_asset/yourFile.xml
I haven´t tried this yet, but I hope it will work
Post a Comment for "Parsing Local Xml File In Android"