Thursday, 28 July 2011

Write element with namespace

  

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

public class MainClass {
  public static void main(String[] argsthrows Exception {
    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
    XMLStreamWriter writer = outputFactory.createXMLStreamWriter(System.out);
    writer.writeStartDocument("1.0");
    writer.writeCharacters("\n");
    writer.writeStartElement("ns1""sample""http://www.e.com/ns1");
    writer.writeNamespace("ns1""http://www.e.com/ns1");

    writer.writeEmptyElement("http://www.e.com/ns1""inner1");
    writer.writeAttribute("otherAttribute""true");
    writer.writeEndElement();
    writer.writeEndDocument();
    writer.flush();
    System.out.println();

  }

}

   
  

No comments:

Post a Comment