Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

XML: empty tag issue

843834Apr 29 2008 — edited Apr 29 2008
I use Transformer class to convert xml Document into string representation:

StringWriter sw = new StringWriter();
TransformerFactory transFactory = TransformerFactory.newInstance();
Transformer transformer = transFactory.newTransformer();

transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setParameter(OutputKeys.ENCODING, "UTF-8");
transformer.transform(new DOMSource(doc), new StreamResult(sw));

but if the content of the tag is empty, the output is in this format: <tag />. Can someone know how to get the following format instead: <tag></tag>?


Thanks,
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 27 2008
Added on Apr 29 2008
7 comments
377 views