简体   繁体   中英

Indent XML in JEditorPane

I am trying to indent XML in a Java JEditorPane, so that this:

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

becomes:

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

I have tried constructing a DocumentBuilder object, and then transforming it with:

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

then set the text in the JEditorPane:

editorPane.setText(do serialization and transformation methods here)

It does not indent the XML however..

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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