List of usage examples for javax.xml.bind JAXBContext createUnmarshaller
public abstract Unmarshaller createUnmarshaller() throws JAXBException;
From source file:DataSet.java
public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(DataSet.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); File xml = new File("input.xml"); DataSet dataSet = (DataSet) unmarshaller.unmarshal(xml); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(dataSet, System.out); }
From source file:Main.java
public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Foo.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); File xml = new File("input.xml"); Foo foo = (Foo) unmarshaller.unmarshal(xml); System.out.println(foo.getBar()); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(foo, System.out); }
From source file:Main.java
public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(WebResponse.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); File xml = new File("input.xml"); WebResponse wr = (WebResponse) unmarshaller.unmarshal(xml); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(wr, System.out); }
From source file:Main.java
public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Root.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); Root root = (Root) unmarshaller.unmarshal(new File("input.xml")); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(root, System.out); }
From source file:Main.java
public static void main(String[] args) throws Exception { XMLInputFactory xif = XMLInputFactory.newFactory(); FileInputStream xml = new FileInputStream("input.xml"); XMLStreamReader xsr = xif.createXMLStreamReader(xml); xsr.nextTag(); // Advance to "Persons" tag xsr.nextTag(); // Advance to "Person" tag JAXBContext jc = JAXBContext.newInstance(Person.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); List<Person> persons = new ArrayList<Person>(); while (xsr.hasNext() && xsr.isStartElement()) { Person person = (Person) unmarshaller.unmarshal(xsr); persons.add(person);/*from www .j a v a2 s . c om*/ xsr.nextTag(); } for (Person person : persons) { System.out.println(person.getName()); } }
From source file:Main.java
public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Items.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); File xml = new File("input.xml"); Items items = (Items) unmarshaller.unmarshal(xml); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(items, System.out); }
From source file:Main.java
public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Property.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); File xml = new File("input.xml"); Property property = (Property) unmarshaller.unmarshal(xml); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(property, System.out); }
From source file:BarAdapter.java
public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Foo.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); File xml = new File("data.xml"); Foo foo = (Foo) unmarshaller.unmarshal(xml); Marshaller marshaller = jc.createMarshaller(); marshaller.setAdapter(new BarAdapter()); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(foo, System.out); }
From source file:Main.java
public static void main(String[] args) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(Home.class, Person.class, Animal.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); StreamSource xml = new StreamSource("input.xml"); Home home = unmarshaller.unmarshal(xml, Home.class).getValue(); for (Object object : home.any) { System.out.println(object.getClass()); }// ww w . jav a 2s. c o m }
From source file:Main.java
public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Graph.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); File xml = new File("input.xml"); Graph graph = (Graph) unmarshaller.unmarshal(xml); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(graph, System.out); }