安卓:读取XML从本地资源(用于测试) [英] Android : Reading XML from local resource (for testing)

查看:99
本文介绍了安卓:读取XML从本地资源(用于测试)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个应用程序,它会从一个web服务(可能通过kSOAP2)读取XML。我相当满意SAX解析,因为我已经做了XML解析iPhone应用程序。

I'm writing an app which will read XML from a webservice (probably via kSOAP2). I'm fairly happy with SAX parsing, as I've done XML parsing iPhone apps.

不幸的是,Web服务是不公开的却又是那么的初始测试中,我有一个包含我需要解析XML的一些文件。在早期开发阶段,我只需要从文件中读取XML并把它传递到XML解析器

Unfortunately the webservice isn't public yet so for initial testing I have some files containing the XML I need to parse. In this early dev phase I just need to read the XML from the files and pass it into the XML parser

Xml.parse(this.testXML, root.getContentHandler());

我如何从文件中读取/资源XML转换成字符串传递到这个方法。我想破解并测试解析器,但这个简单的步骤,抱着我。

How do I read the XML from a file/resource into a string to pass into this method. I want to crack on and test the parser, but this simple step is holding me up.

感谢

推荐答案

创建的的下res文件夹

Create a raw folder under res

摆在那里你的XML文件,例如。 testXML.xml:

Put your XML file in there, eg. testXML.xml:

/res/raw/testXML.xml

您应该可以使用使用你的XML解析器,作为一个InputStream:

You should be able to use your XML parser using that as an inputstream:

Xml.parse(getResources().openRawResource(R.raw.testXML), Xml.Encoding.UTF_8, root.getContentHandler());

试试。

这篇关于安卓:读取XML从本地资源(用于测试)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆