Attribute with Namespace
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;
public class MainClass {
public static void main(String[] args) throws 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();
}
}
Related examples in the same category