在android中读取xml的最佳方法是什么?

时间:2022-02-22 23:13:57

Hi I've an android app which uses an XML file to render its User Interface,And here is the xml

嗨,我有一个Android应用程序,它使用XML文件来呈现其用户界面,这里是xml

<?xml version="1.0" encoding="utf-8"?>
<questions>
<question id="1" label="Name" type="text"></question>
<question id="2" label="Gender" type="select" options="Male,Female,Transgender"></question>
<question id="3" label="Age" type="text"></question>
<question id="4" label="city" type="select" options="Banglore,Hyderabad,Chennai"></question>
</questions>

I am using DOM parser to read xml and I am getting the inputstream using url.openconnection().getInputstream() method.But I want the xml file to be included in my android project folder and use it.How would I go about that ?? so what are the other ways to get the InputStream ??

我正在使用DOM解析器来读取xml,我正在使用url.openconnection()获取输入流.getInputstream()方法。但我希望xml文件包含在我的android项目文件夹中并使用它。我怎么去那个??那么获取InputStream的其他方法是什么?

1 个解决方案

#1


1  

If you place the file in your assets folder, you can use the AssetManager to get an input stream to it.

如果将文件放在assets文件夹中,则可以使用AssetManager获取输入流。

#1


1  

If you place the file in your assets folder, you can use the AssetManager to get an input stream to it.

如果将文件放在assets文件夹中,则可以使用AssetManager获取输入流。