Write Start Document : XMLStreamWriter « XML « Java






Write Start Document

  

import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;

public class MainClass {

  public static void main(String[] args) throws Exception {
    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
    XMLStreamWriter writer = outputFactory.createXMLStreamWriter(System.out);
    writer.writeStartDocument("1.0");
    writer.writeStartElement("person");
    writer.writeStartElement("name");
    writer.writeStartElement("fname");
    writer.writeCharacters("AAA");

    writer.writeEndDocument();
    writer.flush();
  }

}

   
  








Related examples in the same category

1.Write element with namespace
2.Xml Reader To Writer