XML: empty tag issue
843834Apr 29 2008 — edited Apr 29 2008I 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,