0

我有一个保存在 Res->Raw 中的 XML 文件,我想获取这个文件的路径,以便在函数的参数中传递它来解析它。

XML 文件的名称是family.xml,所以我尝试了这个但不起作用:“res/raw/families.xml”。有什么帮助吗?

4

2 回答 2

1

Use :

 InputStream is=getResources().openRawResource(R.raw.families);

to get an InputStream to your XML, and then use XMLPullParser to parse the file :

 XmlPullParser xpp=XmlPullParserFactory.newInstance().newPullParser();
 xpp.setInput(is,"your-encoding");

Another alternative would be to put it in the assets folder.

于 2013-04-09T19:24:56.883 回答
0

res/ is just source folder. It does not exist in final app. If you want to retrieve your file you may want to either put it in assets folder or use getResources().openRawResource()

于 2013-04-09T19:24:43.823 回答