我正在写一个应用程序,它会从一个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());
试试。
上一篇:R能够解决不了 - Android的,没有进口android.R;声明声明、Android、android
下一篇:抛出java.lang.ClassNotFoundException在我的Android应用程序,但我不知道为什么我的、但我、不知道为什么、抛出