tags:

views:

223

answers:

1

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.

+1  A: 

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/>
McDowell
Looks like XMLStreamWriter may be my best choice. Transforming would be the optimal solution but when i'm dealing with 400+ mb files that will be a serious time problem.