Self Closing Tags with XMLEventWriter

Thus, the question largely corresponds to that indicated in the title. I am doing some xml work and using XMLEventWriter. The big problem that I am facing is that I need to create some closing tags

The problem is that I did not understand the way to do this using eventWriter. I tried everything I could think of using XMLEventFactory, but nothing works. Any help would be greatly appreciated.

+4
source share
1 answer

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/> 
+2
source

All Articles