public void addOrUpdateInitDatas(String xmlFilePath){
try {
String filePath = null;
if(xmlFilePath == null || xmlFilePath.trim().equals("")){
filePath = file;
}else{
filePath = xmlFilePath;
}
//DOM4J使用示例
Document document = new SAXReader().read(Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath));
[color=red] importModules( document.selectNodes("//Modules/Module") ,null);[/color] } catch (Exception e) {
e.printStackTrace();
}
}
protected void importModules([color=red]List modules[/color],Module parent){
for (Iterator iter = modules.iterator(); iter.hasNext();) {
[color=red]Element element = (Element) iter.next();[/color]}
}
今天一网友给我留言,问我为什么Element element = (Element) iter.next();这里用的是Element类型呢,不是用的是int、String、long等。
其实很简单:就是因为在for循环里面循环的是list类型,当你仔细观看一下方法importModules(List modules,Module parent)你就不能发现了。
try {
String filePath = null;
if(xmlFilePath == null || xmlFilePath.trim().equals("")){
filePath = file;
}else{
filePath = xmlFilePath;
}
//DOM4J使用示例
Document document = new SAXReader().read(Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath));
[color=red] importModules( document.selectNodes("//Modules/Module") ,null);[/color] } catch (Exception e) {
e.printStackTrace();
}
}
protected void importModules([color=red]List modules[/color],Module parent){
for (Iterator iter = modules.iterator(); iter.hasNext();) {
[color=red]Element element = (Element) iter.next();[/color]}
}
今天一网友给我留言,问我为什么Element element = (Element) iter.next();这里用的是Element类型呢,不是用的是int、String、long等。
其实很简单:就是因为在for循环里面循环的是list类型,当你仔细观看一下方法importModules(List modules,Module parent)你就不能发现了。