Example usage for javax.xml.bind Marshaller JAXB_FORMATTED_OUTPUT

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

Introduction

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

Prototype

String JAXB_FORMATTED_OUTPUT

To view the source code for javax.xml.bind Marshaller JAXB_FORMATTED_OUTPUT.

Click Source Link

Document

The name of the property used to specify whether or not the marshalled XML data is formatted with linefeeds and indentation.

Usage

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 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);//from   w  w  w.  j a v a  2s .  c o m

    m.marshal(object, 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);/* ww w  .ja  v  a  2 s .co m*/

    m.marshal(object, System.out);

    //to a file
    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);//from   w w  w.  ja  v  a  2 s  .  c  o  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);//from  w w  w  .j  a v  a 2  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:Main.java

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

    Response response = new Response();
    response.setMessage("1 < 2");

    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.marshal(response, 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();
    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    // Unmarshal #1 = Default Unmarshal
    System.out.println("Unmarshal #1");
    Root root = (Root) unmarshaller.unmarshal(new StringReader(XML));
    marshaller.marshal(root, System.out);

    // Unmarshal #2 - Override Default ValidationEventHandler
    System.out.println("Unmarshal #2");
    unmarshaller.setEventHandler(new ValidationEventHandler() {
        @Override//from   ww  w .j  a  v  a  2  s.  com
        public boolean handleEvent(ValidationEvent event) {
            System.out.println(event.getMessage());
            return false;
        }
    });
    unmarshaller.unmarshal(new StringReader(XML));
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JAXBContext context = JAXBContext.newInstance(Disk.class, MyStatus.class, MyDisk.class);
    Marshaller m = context.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

    Disk disk = new Disk();
    disk.setStatus("attached");
    disk.setSize(10000000000L);//ww  w.j  av a  2  s. c  o  m
    disk.setFreeSpace(25600000L);
    disk.setId("1");

    m.marshal(disk, System.out);
    m.marshal(new MyStatus(disk), System.out);
    m.marshal(new MyDisk(disk), System.out);
}

From source file:Main.java

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

    Foo foo = new Foo();
    foo.setBar("Hello\nWorld");

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