[英]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:
您可能要说明两件事:
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?
如果是后者,请查看以下答案: 如何在android上将xml转换为html?
To access XML resources stored in res/xml, call getResources().getXml() from any Activity or other Context. 要访问存储在res / xml中的XML资源,请从任何Activity或其他Context调用getResources()。getXml()。 You need to supply to getXml() the ID of the XML to load (R.xml.myfile).
您需要向getXml()提供要加载的XML的ID(R.xml.myfile)。
to read your xml add code as shown below 读取您的xml添加代码,如下所示
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 并获取代码内容,添加如下所示的代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.