1

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

Andrei Petrenko
  • 3,922
  • 3
  • 31
  • 53
user03
  • 29
  • 2
  • 5

2 Answers2

2

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?

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