[英]parse plist from sdcard in android
In my project parse plist from sdcard . 在我的项目中, 从sdcard解析plist 。
I have done one example that takes a xml file from resource belove code. 我已经做了一个示例,该示例从资源belove代码获取一个xml文件。
Resources res = activity.getResources();
XmlResourceParser xpp = res.getXml(R.xml.myplist);
but i want to 但是我要
XmlResourceParser xpp = (SDCARD xml file)
Please ,Help me . 请帮帮我 。
You should substitute the XmlResourceParser
with XmlPullParser
. 您应该将
XmlResourceParser
替换为XmlPullParser
。 The first one is for parsing xml from resources folder, the latter - for parsing xml from InputStream
. 第一个用于从resources文件夹解析xml,第二个用于从
InputStream
解析xml。 From then on you need to construct an InputStream
from the sdcard: 从那时起,您需要从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
EDIT : BTW I am interested in the way you implemented to parse plist in android. 编辑 :顺便说一句,我对您实现解析android中的plist的方式感兴趣。
Just use the java file command for your xml file on sdcard. 只需对sdcard上的xml文件使用java file命令即可。
File file=new File("/mnt/sdcard/example.xml");
and using DOM or SAX parser you can parse the data(information) from it for your application. 并使用DOM或SAX解析器,您可以为应用程序解析其中的数据(信息)。
Thnx. 谢谢
EDIT: parsing local xml file using Sax in android, Read XML Resources in Android, using XmlResourceParser: XML parsing interface or Here or Here Look at these tutorials. 编辑:使用android中的Sax解析本地xml文件,使用XmlResourceParser:使用XmlResourceParser:XML解析接口或此处或此处查看这些教程,阅读Android中的XML资源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.