I am not sure if this is possible using XMLEventWriter . This is possible using XMLStreamWriter .
If you are stuck with XMLEventWriter, you can subsequently convert the data.
Reader xml = new StringReader("<?xml version=\"1.0\"?><foo></foo>"); TransformerFactory transFactory = TransformerFactory.newInstance(); Transformer transformer = transFactory.newTransformer(); transformer.transform(new StreamSource(xml), new StreamResult(System.out));
The output of the above code:
<?xml version="1.0" encoding="UTF-8"?><foo/>
source share