Java xml self-closing tags

jasper-reports, java, xml

Solution

If you add this line before you invoke transformer.transform - the output will be in html style:

transformer.setOutputProperty(OutputKeys.METHOD, "html");

Problem

My Java program looks like: ``` 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(); } } ``` Output is: `<test><test1/></test>` I want output `<test><test1></test1></test>`. Because I'm using JasperReports and html style only allow my wanted output. How to achieve that? Is there any output property of Transformer or any property of DocumentBuilderFactory to do wanted output?

Original source

Related problems