Add basic (but not yet working) XML parsing helper

This commit is contained in:
karl 2019-11-28 20:18:06 +01:00
parent b7a21d4be2
commit cfd481a22b
2 changed files with 21 additions and 1 deletions

View File

@ -7,7 +7,6 @@ import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.util.Calendar;
import java.util.List; import java.util.List;
@Data @Data

View File

@ -0,0 +1,21 @@
package at.technikumwien.movies;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import java.io.File;
import java.util.List;
public class XmlHelper {
public static void moviesToXml(List<Movies> movies,String filename) throws Exception {
JAXBContext jaxbContext = JAXBContext.newInstance(Movies.class);
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
// FIXME: Can't marshal list
marshaller.marshal(movies, System.out);
marshaller.marshal(movies, new File(filename));
}
}