Z
Zsolt
Hi,
I use the code below (jdk-1.4.2-06) to write into XML files. How can I get
an indented output like below:
<top>
<sub>Hello</sub>
<sub2>Hello2</sub2>
<sub3>
<sub4>Hello3</sub4>
</sub3>
</top>
DOMSource source = new DOMSource(root);
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
Properties props = new Properties();
props.setProperty(OutputKeys.ENCODING, "UTF-8");
props.setProperty(OutputKeys.METHOD, "xml");
props.setProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperties(props);
StringWriter ascii = new StringWriter();
StreamResult result = new StreamResult(ascii);
transformer.transform(source, result);
Zsolt
I use the code below (jdk-1.4.2-06) to write into XML files. How can I get
an indented output like below:
<top>
<sub>Hello</sub>
<sub2>Hello2</sub2>
<sub3>
<sub4>Hello3</sub4>
</sub3>
</top>
DOMSource source = new DOMSource(root);
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
Properties props = new Properties();
props.setProperty(OutputKeys.ENCODING, "UTF-8");
props.setProperty(OutputKeys.METHOD, "xml");
props.setProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperties(props);
StringWriter ascii = new StringWriter();
StreamResult result = new StreamResult(ascii);
transformer.transform(source, result);
Zsolt