0

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..

eeijlar
  • 1,232
  • 3
  • 20
  • 53
  • For better help sooner, post an [MCVE](http://stackoverflow.com/help/mcve) (Minimal Complete Verifiable Example) or [SSCCE](http://www.sscce.org/) (Short, Self Contained, Correct Example). – Andrew Thompson Jan 19 '15 at 15:51
  • When you print out the transformed XML, is it correctly indented? – VGR Jan 19 '15 at 17:59

1 Answers1

1

try to use this to format XML: http://java-sl.com/xml_editor_kit.html

roeygol
  • 4,908
  • 9
  • 51
  • 88
  • 1
    This is helpful, but I don't need the level of sophistication that this provides. A simple pretty print does the job. – eeijlar Jan 20 '15 at 11:04