use of com.baeldung.xml.binding.Tutorials in project tutorials by eugenp.
the class JaxbParser method getFullDocument.
public Tutorials getFullDocument() {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(Tutorials.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
Tutorials tutorials = (Tutorials) jaxbUnmarshaller.unmarshal(this.getFile());
return tutorials;
} catch (JAXBException e) {
e.printStackTrace();
return null;
}
}
use of com.baeldung.xml.binding.Tutorials in project tutorials by eugenp.
the class JaxbParser method createNewDocument.
public void createNewDocument() {
Tutorials tutorials = new Tutorials();
tutorials.setTutorial(new ArrayList<Tutorial>());
Tutorial tut = new Tutorial();
tut.setTutId("01");
tut.setType("XML");
tut.setTitle("XML with Jaxb");
tut.setDescription("XML Binding with Jaxb");
tut.setDate("04/02/2015");
tut.setAuthor("Jaxb author");
tutorials.getTutorial().add(tut);
try {
JAXBContext jaxbContext = JAXBContext.newInstance(Tutorials.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(tutorials, file);
} catch (JAXBException e) {
e.printStackTrace();
}
}
use of com.baeldung.xml.binding.Tutorials in project tutorials by eugenp.
the class JaxbParserUnitTest method createNewDocumentTest.
@Test
public void createNewDocumentTest() {
File newFile = new File("src/test/resources/example_jaxb_new.xml");
parser = new JaxbParser(newFile);
parser.createNewDocument();
assertTrue(newFile.exists());
Tutorials tutorials = parser.getFullDocument();
assertNotNull(tutorials);
assertTrue(tutorials.getTutorial().size() == 1);
assertTrue(tutorials.getTutorial().get(0).getTitle().equalsIgnoreCase("XML with Jaxb"));
}
use of com.baeldung.xml.binding.Tutorials in project tutorials by eugenp.
the class JaxbParserUnitTest method getFullDocumentTest.
@Test
public void getFullDocumentTest() {
parser = new JaxbParser(new File(fileName));
Tutorials tutorials = parser.getFullDocument();
assertNotNull(tutorials);
assertTrue(tutorials.getTutorial().size() == 4);
assertTrue(tutorials.getTutorial().get(0).getType().equalsIgnoreCase("java"));
}
Aggregations