【问题标题】:Parse a local xml file and show parsed data in web-view解析本地 xml 文件并在 web 视图中显示解析的数据
【发布时间】:2012-02-01 11:12:40
【问题描述】:

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

【问题讨论】:

    标签: android xml


    【解决方案1】:

    我们需要更多关于您想要做什么的信息。这是非常不清楚的。您可能意味着两件事:

    1. XML 文件是 XHMTL 文件,您希望在 web 视图中呈现和显示。
    2. 您希望将样式应用于 XML 文件并将其显示在 Web 视图中,最好使用 XSLT。

    在前一种情况下,它非常简单。如果是后者,看看这个答案:How can I transform xml to html on android?

    【讨论】:

      【解决方案2】:

      要访问存储在 res/xml 中的 XML 资源,请从任何 Activity 或其他 Context 调用 getResources().getXml()。您需要向 getXml() 提供要加载的 XML 的 ID (R.xml.myfile)。

      读取你的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.
      

      要获取代码内容,请添加如下所示的代码

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-09-21
        • 1970-01-01
        • 2010-11-25
        • 1970-01-01
        • 1970-01-01
        • 2012-11-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多