【问题标题】:xml file parsing in androidandroid中的xml文件解析
【发布时间】:2010-08-10 10:50:02
【问题描述】:

如何解析位于系统硬盘中的本地 XML 文件?

【问题讨论】:

    标签: android xml-parsing


    【解决方案1】:

    如果您的文件位于 /sdcard 目录中,则可以使用

    InputStream in = new FileInputStream("/sdcard/myfile.xml");
    

    如果它位于您应用的数据目录中,您可以使用

    File f1=new File(context.getFilesDir(), "myfile.xml");
    InputStream in = new FileInputStream(f1);
    

    如果它位于您的 assets/ 目录中,您可以使用:

    AssetManager assets = context.getAssets();
    InputStream in = assets.open("myfile.xml");
    

    之后,您可以使用 DOM 或 SAX 进行 XML 解析

    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document doc = builder.parse(in);
    

    【讨论】:

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