XMLEventFactory: createAttribute(String prefix, String namespaceURI, String localName, String value) : XMLEventFactory « javax.xml.stream « Java by API






XMLEventFactory: createAttribute(String prefix, String namespaceURI, String localName, String value)

  

import javax.xml.stream.XMLEventFactory;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLOutputFactory;

public class MainClass {

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

    writer.add(eventFactory.createStartElement("ns1", "http://www.e.com/ns1", "sample", null,
        null));
    writer.add(eventFactory.createNamespace("ns1", "http://www.e.com/ns1"));
    writer.add(eventFactory.createNamespace("ns2", "http://www.e.com/ns2"));
    writer.add(eventFactory.createAttribute("ns2", "http://www.e.com/ns2", "attribute","true"));
    writer.add(eventFactory.createEndDocument());
    writer.flush();
  }

}

   
    
  








Related examples in the same category

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