在 JEditorPane 中缩进 XML



我正在尝试在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

最新更新