Example usage for javax.xml.bind JAXBContext createMarshaller

List of usage examples for javax.xml.bind JAXBContext createMarshaller

Introduction

In this page you can find the example usage for javax.xml.bind JAXBContext createMarshaller.

Prototype

public abstract Marshaller createMarshaller() throws JAXBException;

Source Link

Document

Create a Marshaller object that can be used to convert a java content tree into XML data.

Usage

From source file:Main.java

public static void main(String[] args) throws JAXBException {
    JAXBContext context = JAXBContext.newInstance(Card.class);
    context.createMarshaller().marshal(Card.CLUBS, System.out);
}

From source file:Weird.java

public static void main(String[] args) throws JAXBException {
    Weird w = new Weird();
    w.value = "foo";
    w.svalue = "bar";
    JAXBContext context = JAXBContext.newInstance(Weird.class);
    context.createMarshaller().marshal(w, System.out);
}

From source file:Weird.java

public static void main(String[] args) throws JAXBException {
    Weird w = new Weird();
    w.myValue = "foo";
    w.svalue = "bar";
    JAXBContext context = JAXBContext.newInstance(Weird.class);
    context.createMarshaller().marshal(w, System.out);
}

From source file:Main.java

public static void main(String[] args) throws JAXBException {
    Animal tiger = new Animal();
    tiger.setType("A");
    tiger.setValue("Tiger");

    JAXBContext jaxbContext = JAXBContext.newInstance(Animal.class);
    Marshaller m = jaxbContext.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    m.marshal(tiger, System.out);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JAXBContext jxbc = JAXBContext.newInstance(Main.class);
    Marshaller marshaller = jxbc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
    marshaller.marshal(new JAXBElement(new QName("root"), Main.class, new Main("test")), System.out);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    XMLStreamWriter writer = XMLOutputFactory.newFactory().createXMLStreamWriter(System.out);
    writer.setDefaultNamespace("http://www.java2s.com");

    JAXBContext jc = JAXBContext.newInstance(WorkSet.class);
    Marshaller m = jc.createMarshaller();
    m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);

    writer.writeStartDocument();//from  www  .j  a v a  2 s .  c o  m
    writer.writeStartElement("http://www.java2s.com", "Import");
    writer.writeNamespace("", "http://www.java2s.com");
    writer.writeStartElement("WorkSets");

    m.marshal(new WorkSet(), writer);
    m.marshal(new WorkSet(), writer);

    writer.writeEndDocument();
    writer.close();
}

From source file:Main.java

public static void main(String[] args) throws JAXBException {
    Child child = new Child();
    child.age = 55;//from  ww w .j  a  v  a  2s .c  o m
    Main parent = new Main();
    parent.child = child;
    JAXBContext context = JAXBContext.newInstance(Main.class);
    Marshaller marshaller = context.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    marshaller.marshal(parent, System.out);
}

From source file:MyPerson.java

public static void main(String[] args) throws JAXBException {
    MyPerson p = new MyPerson();
    p.first = "l";
    p.last = "h";

    JAXBContext context = JAXBContext.newInstance(MyPerson.class);
    Marshaller marshaller = context.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.marshal(p, System.out);
}

From source file:Main.java

public static void main(String[] args) throws JAXBException {
    JAXBContext context = JAXBContext.newInstance(PayTypeList.class);
    Marshaller m = context.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    PayTypeList paymentType = new PayTypeList();

    List<String> paymentTypes = new ArrayList<String>();
    paymentTypes.add("one");
    paymentTypes.add("two");
    paymentTypes.add("three");
    paymentType.setPayType(paymentTypes);

    m.marshal(paymentType, System.out);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JAXBContext jc = JAXBContext.newInstance(Field.class);
    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    Field field = new Field();
    field.name = "myField";
    marshaller.marshal(field, System.out);

    field.status = "citizen";
    field.country = "England";
    marshaller.marshal(field, System.out);

    field.status = null;/*www . ja  v a2 s .  c o  m*/
    marshaller.marshal(field, System.out);
}