Example usage for javax.xml.bind Marshaller marshal

List of usage examples for javax.xml.bind Marshaller marshal

Introduction

In this page you can find the example usage for javax.xml.bind Marshaller marshal.

Prototype

public void marshal(Object jaxbElement, javax.xml.stream.XMLEventWriter writer) throws JAXBException;

Source Link

Document

Marshal the content tree rooted at jaxbElement into a javax.xml.stream.XMLEventWriter .

Usage

From source file:MyAbstractClass.java

public static void main(String[] args) throws JAXBException {

        MyClass my = new MyClass();
        my.setDataType("data type");
        my.setMatch("STRING MATCH");
        my.setValue("value");

        JAXBContext context = JAXBContext.newInstance(MyClass.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(my, System.out);
    }/* ww w  .  j  av a 2  s  . c o m*/

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:Main.java

public static void main(String[] args) throws Exception {
    JAXBContext jc = JAXBContext.newInstance(Bar.class);

    Bar bar = new Bar();
    bar.setAtt1("a");
    bar.setAtt2("b");

    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.marshal(bar, System.out);
}

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 {
    Root root = new Root();

    Book cDev = new Book();
    cDev.setName("C Development");
    root.getEmployeeDesiredSkills().add(cDev);

    Book perlDev = new Book();
    perlDev.setName("Perl Development");
    root.getEmployeeDesiredSkills().add(perlDev);

    JAXBContext jc = JAXBContext.newInstance(Root.class);
    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 {
    JAXBContext jc = JAXBContext.newInstance(Child.class);
    Child child = new Child();
    child.setParentProperty1("parentProperty1");
    child.setParentProperty2("parentProperty2");
    child.setChildProperty("childProperty");

    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.marshal(child, System.out);
}

From source file:Main.java

public static void main(String[] args) throws Exception {

    MyMessage sarm = new MyMessage();
    MyGroupResponse[] sgr = new MyGroupResponse[2];
    sgr[0] = new MyGroupResponse();
    sgr[1] = new MyGroupResponse();
    sarm.setSailingGroup(sgr);/*from  w ww.  ja  v a 2  s. co  m*/

    JAXBElement<MyMessage> rootElement = new JAXBElement<MyMessage>(new QName("root"), MyMessage.class, sarm);

    JAXBContext jc = JAXBContext.newInstance(MyMessage.class, MyGroup.class, MyGroupResponse.class);
    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.marshal(rootElement, System.out);

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JAXBContext jc = JAXBContext.newInstance(Root.class);

    Root root = new Root();
    DatatypeFactory dtf = DatatypeFactory.newInstance();
    root.month = dtf.newXMLGregorianCalendar("--11");

    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 {
    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);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JAXBContext jc = JAXBContext.newInstance(Address.class);

    StringReader xml = new StringReader("<Address><Name>Test</Name></Address>");
    Unmarshaller unmarshaller = jc.createUnmarshaller();
    Address address = (Address) unmarshaller.unmarshal(xml);

    System.out.println(address.getPostalAddress().getState());

    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.marshal(address, System.out);
}