So the question is pretty much as stated in the title. I am doing some xml work and using XMLEventWriter. The big issue I'm having is that I need to create some self closing tags
The problem is that I haven't figured out a way to do this with the eventWriter. I have tried everything I can think of using XMLEventFactory but nothing seems to work. Any help would be greatly appreciated.
I'm not sure if this is possible using XMLEventWriter. It is certainly possible with XMLStreamWriter.
If you are stuck with XMLEventWriter, you could transform the data afterwards.
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 is:
<?xml version="1.0" encoding="UTF-8"?><foo/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With