XMLStreamWriter: writeEmptyElement(String localName) : XMLStreamWriter « javax.xml.stream « Java by API






XMLStreamWriter: writeEmptyElement(String localName)

  

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

public class Main {

    public static void main(String[] args) throws Exception {
        XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
        XMLStreamWriter writer = outputFactory.createXMLStreamWriter(System.out);
        writer.writeStartDocument("1.0");
        writer.writeStartElement("addresses");
        writer.writeStartElement("address");
        writer.writeAttribute("type", "work");
        writer.writeStartElement("street");
        writer.writeCharacters("1111 Ave");
        writer.writeComment("comments");
        writer.writeEndElement();
        writer.writeEmptyElement("inner");
        writer.flush();
        System.out.println();
        writer.writeAttribute("otherAttribute", "true");
        writer.flush();
        System.out.println();
        writer.writeEndElement();
        writer.writeEndElement();
        writer.writeEndDocument();
        writer.flush();
    }
}

   
    
  








Related examples in the same category

1.XMLStreamWriter: flush()
2.XMLStreamWriter: writeAttribute(String localName, String value)
3.XMLStreamWriter: writeEmptyElement(String namespaceURI, String localName)
4.XMLStreamWriter: writeEndDocument()
5.XMLStreamWriter: writeEndElement()
6.XMLStreamWriter: writeNamespace(String prefix, String namespaceURI)
7.XMLStreamWriter: writeStartDocument(String version)
8.XMLStreamWriter: writeStartElement(String prefix, String localName, String namespaceURI)