您的位置:首页 > 编程语言 > Java开发

Java生成XML时,换行和缩进

2015-12-17 14:57 751 查看
<pre name="code" class="java">        TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
Source xmlSource = new DOMSource(document);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Result transformResult = new StreamResult(baos);
transformer.transform(xmlSource, transformResult);



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: