【问题标题】:parse plist from sdcard in android从android中的sdcard解析plist
【发布时间】:2012-12-16 03:41:24
【问题描述】:

在我的项目中从 sdcard 解析 plist

我已经做了一个从资源代码中获取 xml 文件的示例。

 Resources res = activity.getResources();
 XmlResourceParser xpp = res.getXml(R.xml.myplist);

但我想

     XmlResourceParser xpp = (SDCARD xml file)
  1. 如何解决我的问题,尝试了很多但我无法解决我的问题 问题,

请帮帮我

【问题讨论】:

  • 您可以提高接受率以吸引更多 SO 用户。

标签: android xml plist inputstream


【解决方案1】:

您应该将XmlResourceParser 替换为XmlPullParser。第一个用于解析资源文件夹中的 xml,后者用于解析来自 InputStream 的 xml。从那时起,您需要从 sdcard 构造一个InputStream

File file = new File (path-to-your-file);
fileInputStream fis = new FileInputStream(file);
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();

xpp.setInput(fis, "UTF-8");// or whatever encoding suites you

编辑:顺便说一句,我对您实现在 android 中解析 plist 的方式很感兴趣。

【讨论】:

    【解决方案2】:

    只需对 sdcard 上的 xml 文件使用 java file 命令即可。

    File file=new File("/mnt/sdcard/example.xml");
    

    使用 DOM 或 SAX 解析器,您可以为您的应用程序解析其中的数据(信息)。

    谢谢。

    编辑:在 android 中使用 Sax 解析本地 xml 文件,在 Android 中读取 XML 资源,使用 XmlResourceParser:XML 解析接口或 Here 或 Here 看这些教程。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-26
      • 2014-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-12
      • 1970-01-01
      相关资源
      最近更新 更多