I have an xml file which is stored locally in my app and I want to show parsed data from it in web-view.
Asked
Active
Viewed 859 times
2 Answers
2
We need more information regarding what exactly you want to do. It is very unclear. There are two things that you could mean:
- The XML file is an XHMTL file, that you want to render and show in a webview.
- You want to apply styling to an XML file and display it in the webview, preferably using XSLT.
In the former case, it is pretty straightforward. If it is the latter, check out this answer: How can I transform xml to html on android?

Community
- 1
- 1

Rohan Prabhu
- 7,180
- 5
- 37
- 71
1
To access XML resources stored in res/xml, call getResources().getXml() from any Activity or other Context. You need to supply to getXml() the ID of the XML to load (R.xml.myfile).
to read your xml add code as shown below
XmlResourceParser myxml = mContext.getResources().getXml(R.xml.MyXml);
//MyXml.xml is name of our xml in newly created xml folder, mContext is the current context
// Alternatively use: XmlResourceParser myxml = getContext().getResources().getXml(R.xml.MyXml);
myxml.next();//Get next parse event
int eventType = myxml.getEventType(); //Get current xml event i.e., START_DOCUMENT etc.
and to get content of code add code shown below

Navdroid
- 4,453
- 7
- 29
- 47