我正在尝试使用xstream解析XML。以下是XML文件的外观:
<Book>
<type name="story" value="true" />
<type name="history" value="true" />
</Book>
解析此xml的代码如下:
public class Parsing_Xml {
public static void main(String[] args) throws FileNotFoundException {
FileReader fileReader = new FileReader("book.xml"); // load our xml file
XStream xStream = new XStream();
xStream.processAnnotations(Book.class);
Book bookObject = (Book) xStream.fromXML(fileReader);
System.out.println(bookObject.type);
}
@XStreamAlias("Book")
class Book {
@XStreamImplicit
List<String> type = new ArrayList<String>();
}
}
这是我得到的输出:
[, ]
为什么这不会填充XML中存在的所有类型的数组?