Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;

public class Main {

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

    @XmlRootElement(name = "WorkSet", namespace = "http://www.java2s.com")
    public static class WorkSet {

    }
}