Monday, 1 August 2011

Attribute 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.writeStartElement("ns1""sample""http://www.e.com/ns1");
    writer.writeNamespace("ns1""http://www.e.com/ns1");

    writer.writeAttribute("http://www.e.com/ns2""attribute""true");
    writer.writeEmptyElement("http://www.e.com/ns1""inner");
    writer.writeEmptyElement("ns2""inner""http://www.e.com/ns2");
    writer.writeEndElement();
    writer.writeEndDocument();
    writer.flush();
  }
}

   
    
    
    
    
  

No comments:

Post a Comment