xml file parsing in android
How can I parse my local XML file located in the sy开发者_开发问答stems hard disk?
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");
After that you can use DOM or SAX to do your XML parsing
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(in);
精彩评论