XMLEventFactory: createStartElement(QName name, Iterator attributes, Iterator namespaces) : XMLEventFactory « javax.xml.stream « Java by API






XMLEventFactory: createStartElement(QName name, Iterator attributes, Iterator namespaces)

  
import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventFactory;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.events.XMLEvent;

public class Main {

  public static void main(String[] args) throws Exception {
    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
    XMLEventFactory eventFactory = XMLEventFactory.newInstance();
    XMLEventWriter writer = outputFactory.createXMLEventWriter(System.out);

    writer.add(eventFactory.createStartDocument("UTF-8", "1.0"));
    writer.add(eventFactory.createStartElement(new QName("p"), null, null));
    XMLEvent sampleElement = eventFactory.createStartElement("", null, "s", null, null);
    writer.add(sampleElement);
    writer.add(eventFactory.createEndElement("", null, "s"));
    writer.add(sampleElement);
    writer.add(eventFactory.createEndDocument());
    writer.flush();
  }

}

   
    
  








Related examples in the same category

1.XMLEventFactory: createAttribute(String localName, String value)
2.XMLEventFactory: createAttribute(String prefix, String namespaceURI, String localName, String value)
3.XMLEventFactory: createCharacters(String content)
4.XMLEventFactory: createEndDocument()
5.XMLEventFactory: createEndElement(String prefix, String namespaceUri, String localName)
6.XMLEventFactory: createNamespace(String prefix, String namespaceUri)
7.XMLEventFactory: createStartDocument(String encoding, String version)
8.XMLEventFactory: createStartElement(String prefix, String namespaceUri, String localName)
9.XMLEventFactory: createStartElement(String prefix, String namespaceUri, String localName, Iterator attributes, Iterator namespaces)