Create empty element from XMLStreamWriter : XMLStreamWriter « XML « Java Tutorial






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

public class EmptyElement {

  public static void main(String[] args) throws Exception {
    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
    XMLStreamWriter writer = outputFactory.createXMLStreamWriter(System.out);
    writer.writeEmptyElement("empty");
    writer.writeAttribute("attribute", "true");
    writer.writeEndDocument();
    writer.flush(); // write /> to the console
  }
}








33.15.XMLStreamWriter
33.15.1.XMLStreamWriter
33.15.2.Create empty element from XMLStreamWriter