XMLStreamWriter xmlStreamWriter = factory.createXMLStreamWriter(outputStream); xmlStreamWriter.writeStartElement("root"); xmlStreamWriter.writeNamespace("ns", "http://www.example.com/ns"); xmlStreamWriter.writeEndElement();
xmlStreamWriter.writeStartElement("ns", "element", "http://www.example.com/ns"); xmlStreamWriter.writeNamespace("ns", "http://www.example.com/ns"); xmlStreamWriter.writeEndElement();In this example, we use the ```writeStartElement()``` method to write an element with the prefix "ns", the localName "element", and the namespace URI "http://www.example.com/ns". We then declare the namespace with the ```writeNamespace()``` method and close the element with the ```writeEndElement()``` method. Package Library: javax.xml.stream