如何从drawable文件夹Android获取xml文件

时间:2013-01-01 12:18:29

标签: java android xml android-layout

我在我使用的应用程序的网页http://api.androidhive.info/music/music.xml上有一个xml文件

static final String URL = "http://api.androidhive.info/music/music.xml";
String xml = parser.getXmlFromUrl(URL);

工作正常但知道我已将此文件放在我的Android资源文件夹中。那么如何从像这个R.drawble.music.xml而不是网页的android drawable文件夹中获取我的文件。 http://api.androidhive.info/music/music.xml

1 个答案:

答案 0 :(得分:0)

将xml放入/res/raw文件夹。

然后使用:

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

然后使用此解析器XML PULL PARSER

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

感谢。

相关问题