如何解析android的多个XML文件 [英] How to parse multiple xml files in android
问题描述
我有8 XML文件,我能够使用SAX解析一个单一的文件,但有一个方法来解析所有文件。所有的8个文件也有类似的元素,我必须让每个文件的主题列表视图,如含8话题列表视图。如何做到这一点,如何从资产的文件夹中动态调用每个文件。帮助我的一些想法,我坚持这个朋友。在此先感谢
i have 8 xml files and i am able to parse a single file using sax but is there a way to parse all files. all 8 files have similar elements and i have to get the topic of each file in a list view, like list view containing 8 topics. how to do this, how to call each file dynamically from assets folder. Help me with some ideas, am stuck with this friends. Thanks in advance
推荐答案
创建一个实例集合携带汇总parseing结果
create方法来处理返回集合一个XML文件
通过调用函数和添加的结果到集合创建环路,用于文件的方法
create a instance Collection which carry the aggregated parseing result create method to process a single xml file that returns a collection create a method that loops for files by calling the function and adding the result to the collection
/**
* 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;
}
这篇关于如何解析android的多个XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!