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

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

    Tag tag = new Tag();
    tag.setAttribute1(Tag.Foo.A);//from w ww .  j a v  a2  s. com
    System.out.println(tag.getAttribute1());
    marshaller.marshal(tag, System.out);

    tag.setAttribute1(Tag.Foo.B);
    System.out.println(tag.getAttribute1());
    marshaller.marshal(tag, System.out);
}

From source file:Main.java

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

    Marshaller m = context.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    Employee object = new Employee();
    object.setCode("CA");
    object.setName("Tom");
    object.setSalary(300);//  w  w w  . ja  v  a2  s .c  om

    m.marshal(object, System.out);

}

From source file:Main.java

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

    Type type = new Type();

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

From source file:JavaToXMLDemo.java

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

    Marshaller m = context.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    Employee object = new Employee();
    object.setCode("CA");
    object.setName("Cath");
    object.setSalary(300);//from   w  w w .jav a 2 s. co m

    m.marshal(object, new FileOutputStream("result.xml"));

}

From source file:JavaToXMLDemo.java

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

    Marshaller m = context.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    Employee object = new Employee();
    object.setCode("CA");
    object.setName("Cath");
    object.setSalary(300);//  w  w  w.  j  av  a2s . c om

    m.marshal(object, System.out);

}

From source file:Main.java

public static void main(String[] args) throws JAXBException {
    Person p = new Person();
    p.setFirstName("B");
    p.setLastName("H");
    PersonName pn = new PersonName();
    pn.setValue("L");
    p.setFriend(pn);//from www . ja  v a  2s . c  om
    JAXBContext context = JAXBContext.newInstance(Person.class);
    context.createMarshaller().marshal(p, 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 context = JAXBContext.newInstance(Employee.class);

    Marshaller m = context.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    Employee object = new Employee();
    object.setCode("CA");
    object.setName("Cath");
    object.setSalary(300);/*from  w w w.  java2 s.  co  m*/

    m.marshal(object, System.out);

    //to a file
    m.marshal(object, new FileOutputStream("result.xml"));

}

From source file:Main.java

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

    Main event = new Main();
    event.setDate(new Date());
    event.setDescription("im rick james");

    marshaller.marshal(event, System.out);
}

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);
    }/*w  ww.  j  a  v a  2s. co  m*/