0
我需要批量寫入數據到xml。Spring Jaxb2:如何將批處理數據追加到XML文件中而不將它讀到內存中?
有以下域對象:
@XmlRootElement(name = "country")
public class Country {
@XmlElements({@XmlElement(name = "town", type = Town.class)})
private Collection<Town> towns = new ArrayList<>();
....
}
和:
@XmlRootElement(name = "town")
public class Town {
@XmlElement
private String townName;
// etc
}
我marhalling對象與JAXB2。配置如下:
marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(Country.class, Town.class);
因爲簡單編組不在這裏工作作爲marhaller.marshall(fileName, country)
- 它malformes XML。
有沒有辦法馴服marhaller,以便它會創建文件,如果它不存在與所有marhalled數據或如果存在只是追加它在xml文件的末尾?
此外,由於這些文件可能很大,我不想在內存中讀取整個文件,追加數據,然後寫入磁盤。