这是您需要从文档中使用的方式:
http://simple.sourceforge.net/download/stream/doc/tutorial/tutorial.php#scatter
祝你好运。
分散内联元素条目
散布在整个 XML 文档中的元素可以通过内联列表和内联映射来收集。只需为列表或映射要收集的 XML 元素名称提供条目名称,它们将被提取并放入集合对象中。例如,采用以下 XML 元素。它包含没有特定顺序的包含和排除 XML 元素。即使它们没有任何顺序,反序列化过程也能够收集遇到的 XML 元素。
<fileSet path="/user/niall">
<include pattern=".*.jar"/>
<exclude pattern=".*.bak"/>
<exclude pattern="~.*"/>
<include pattern=".*.class"/>
<exclude pattern="images/.*"/>
</fileSet>
为了实现这一点,可以使用以下目标。这声明了两个内联集合,它们指定了它们正在收集的条目对象的名称。如果未指定 entry 属性,则将使用对象的名称。
@Root
public class FileSet {
@ElementList(entry="include", inline=true)
private List<Match> include;
@ElementList(entry="exclude", inline=true)
private List<Match> exclude;
@Attribute
private File path;
private List<File> files;
public FileSet() {
this.files = new ArrayList<File>();
}
@Commit
public void commit() {
scan(path);
}
private void scan(File path) {
File[] list = path.listFiles();
for(File file : list) {
if(file.isDirectory()) {
scan(path);
} else {
if(matches(file)) {
files.add(file);
}
}
}
}
private boolean matches(File file) {
for(Match match : exclude) {
if(match.matches(file)) {
return false;
}
}
for(Match match : include) {
if(match.matches(file)) {
return true;
}
}
return false;
}
public List<File> getFiles() {
return files;
}
@Root
private static class Match {
@Attribute
private String pattern;
public boolean matches(File file) {
Stirng path = file.getPath();
if(!file.isFile()) {
return false;
}
return path.matches(pattern);
}
}
}