How can I display an XML Document in a JEditorPane?

Sandip Chitale

You will have to write a custom subclass of javax.swing.text.StyledEditorKit and also implement the javax.swing.text.ViewFactory.

Please look into the


and the


for how to build an editor kit and the parser.

I think SAX XML parser (call back based) may work better. HTMLEditor kit is based on a callback parser. SAX works better because the javax.swing.text already has it's own object model (javax.swing.text.Document interfaces and javax.swing.text.StyledDocument class). This however does not mean you cannot use DOM parser, only thing is you will have to do more work to integrate DOM (document object model) into the text packages view system.