繁体   English   中英

在JEditorPane中缩进XML

[英]Indent XML in JEditorPane

我正在尝试缩进Java JEditorPane中的XML,这样:

<mytag>
<tag1>
</tag1>
</mytag>

变成:

<mytag>
    <tag1>
    </tag1>
</mytag>

我尝试构造一个DocumentBuilder对象,然后使用以下方法对其进行转换:

serializer.setOutputProperty(OutputKeys.INDENT, "yes")
serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");

然后在JEditorPane中设置文本:

editorPane.setText(do serialization and transformation methods here)

但是,它不会缩进XML。

尝试使用它来格式化XML: http : //java-sl.com/xml_editor_kit.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM