简体   繁体   中英

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

我有一个xml文件,该文件存储在我的应用程序本地,我想在Web视图中显示从中解析的数据。

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM