stax and writing xml
I searched and didn't find anything on this. Hopefully it's a simple question.
I'm using stax to write xml to an output stream and I'd like to be able to generate self closed elements.
i.e. I want to create <foo id="2" name="bar"/>
not <foo id="2" name="bar"></foo>
The only way I can see to write it out is as follows:
writer.writeStartElement("foo" );
writer.writeAttribute("id","2");
writer.writeAttribute("name","bar" );
writer.writeEndElement();
which produces the empty closing tags.
Any ideas?
thanks
-k
[842 byte] By [
kent_ha] at [2007-11-26 19:59:35]

# 4
In general, controlling this isn't easy, you may try using writeEmptyElement() but I don't believe it makes any guarantees about how closing tags are serialized.
If large data sets is a big problem in your application, and readability isn't a primary concern, you may try using Fast Infoset,
https://fi.dev.java.net
which is now part of the platform in JDK 6. Using this format you can improve your application's performance and reduce bandwidth requirements by half, without having to re-write your application. For example JAX-WS, the WS API, already supports this format. Morever, it includes an HTTP-based content negotiation algorithm to make the use of the format completely transparent.