量産メモ帳

忘れっぽいのでメモを残しています。浅く適当に書きます。

2012-11-30から1日間の記事一覧

XMLファイルの中身をPOJOのリストに変換する。

XMLファイル名が"pojos.xml"、ルート要素が"PojoRoot"という前提で、以下の様な感じで行ける。 List loadFromXml() throws Exception { Unmarshaller unmarshaller = JAXBContext.newInstance(AnyNameWillDo.class).createUnmarshaller(); JAXBElement eleme…

POJOのリストをXMLファイルに保存する。

こんな感じで行けた。 void saveToXml(List pojoList) throws Exception { Pojo[] pojos = pojoList.toArray(new Pojo[0]); Marshaller marshaller = JAXBContext.newInstance(pojos.getClass()).createMarshaller(); marshaller.marshal(new JAXBElement(ne…