// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

public class CreateStAX {
    public static void main(String[] args) {
        try {
            XMLOutputFactory xof = XMLOutputFactory.newInstance();
            XMLStreamWriter xsw = xof.createXMLStreamWriter(System.out);
            xsw.writeStartDocument();
            xsw.writeStartElement("all");
            xsw.writeStartElement("one");
            xsw.writeCharacters("A");
            xsw.writeEndElement();
            xsw.writeStartElement("one");
            xsw.writeCharacters("BB");
            xsw.writeEndElement();
            xsw.writeStartElement("one");
            xsw.writeCharacters("CCC");
            xsw.writeEndElement();
            xsw.writeEndElement();
            xsw.writeEndDocument();
            xsw.close();
        } catch (XMLStreamException e) {
            e.printStackTrace();
        }
    }
}
