Java xml self-closing tags

Dukes_Lady

New Member
My Java program looks like:\[code\]public static void main(String[] args) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db; try { db = dbf.newDocumentBuilder(); Document document = db.parse(new ByteArrayInputStream("<test><test1></test1></test>".getBytes("UTF-8"))); StringWriter stringWriter = new StringWriter(); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.setOutputProperty(OutputKeys.INDENT, "no"); transformer.setOutputProperty(OutputKeys.STANDALONE, "yes"); transformer.transform(new DOMSource(document), new StreamResult(stringWriter)); System.out.println(stringWriter.toString()); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (TransformerConfigurationException e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); }}\[/code\]Output is: \[code\]<test><test1/></test>\[/code\] I want output \[code\]<test><test1></test1></test>\[/code\].Because I'm using JasperReports and html style only allow my wanted output. How to achive that? Is there any output property of Transformer or any property of DocumentBuilderFactory to do wanted output?
 
Back
Top