[英]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.