user03
user03

Reputation: 29

Parse a local xml file and show parsed data in web-view

I have an xml file which is stored locally in my app and I want to show parsed data from it in web-view.

Upvotes: 1

Views: 864

Answers (2)

Navdroid
Navdroid

Reputation: 4533

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

Upvotes: 1

Rohan Prabhu
Rohan Prabhu

Reputation: 7302

We need more information regarding what exactly you want to do. It is very unclear. There are two things that you could mean:

  1. The XML file is an XHMTL file, that you want to render and show in a webview.
  2. 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?

Upvotes: 2

Related Questions