我有8个xml文件,我可以使用sax解析单个文件,但是有办法解析所有文件。所有8个文件都有类似的元素,我必须在列表视图中获取每个文件的主题,例如包含8个主题的列表视图。如何做到这一点,如何从assets文件夹动态调用每个文件。帮助我一些想法,我被这些朋友困住了。提前致谢
答案 0 :(得分:1)
要从Assets文件夹中获取xml,请使用
AssetManager mgr = getAssets();
Inputstream ins = mgr.open("abc.xml");
将其解码为xml内容,然后解析它并将您的值存储在arraylist中。 像这样做8个文件并将值存储在同一个arraylist中,最后在listview中显示列表。
答案 1 :(得分:1)
创建一个带有聚合解析结果的实例Collection create方法来处理返回集合的单个xml文件 通过调用函数并将结果添加到集合
来创建一个循环文件的方法/**
* this will process file by file
*
* @param xmlFilePath
* @return
*/
private Collection<String> parseSingleFile(String xmlFilePath) {
// process xml file and extract the result into a collection
return new ArrayList<String>();
}
/**
* this will take all of your files
*
* @param files
* @return
*/
public Collection<String> processBulkFiles(String[] files) {
Collection<String> parsedresults = new ArrayList<String>();
for (String xmlFilePath : files) {
parsedresults.addAll(parseSingleFile(xmlFilePath));
}
return parsedresults;
}
答案 2 :(得分:0)
不知道我是否正确解读,但您可以将列表视图中单击的XML的文件名传递给下一个活动,并使用它来执行XML操作。