XML文件解析的机器人 [英] xml file parsing in android
本文介绍了XML文件解析的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎样才能解析位于系统我的本地XML文件的硬盘?
How can I parse my local XML file located in the systems hard disk?
推荐答案
如果您的文件位于/ SD卡目录,你可以使用
If your file is located in the /sdcard dir, you can use
InputStream in = new FileInputStream("/sdcard/myfile.xml");
如果它位于您的应用程序的数据目录,你可以使用
If its located in your app's data directory, you can use
File f1=new File(context.getFilesDir(), "myfile.xml");
InputStream in = new FileInputStream(f1);
如果它位于你的资产/目录中,你可以使用:
If its located inside your assets/ directory, you can use:
AssetManager assets = context.getAssets();
InputStream in = assets.open("myfile.xml");
之后,你可以使用DOM和SAX做你的XML解析
After that you can use DOM or SAX to do your XML parsing
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(in);
这篇关于XML文件解析的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文