• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1073
  • Last Modified:

Convert XML to HTML and display on to JEditorPane

I have A code to convert XML to HTML like

Document doc = buildDocument();
File styleSheet=new File("makehtml.xsl");
StreamSource styleSource=new StreamSource(styleSheet);
Transformer t = TransformerFactory
            .newInstance().newTransformer(styleSource);                  
ByteArrayOutputStream bout = new ByteArrayOutputStream();
t.transform(new DOMSource(doc), new StreamResult(bout));

Now I want to display the HTML in a JEditorPane. My current code is like

bout.toByteArray()
ByteArrayInputStream bin = new ByteArrayInputStream(data);
JEditorPane editorPane=new JEditorPane();
editorPane.read(bin, new HTMLDocument());


but this displays the source code(tags) of HTML. How can I display the html correctly?
0
csound
Asked:
csound
  • 3
1 Solution
 
CEHJCommented:
Have you called

editorPane.setContent("text/html");

?
0
 
CEHJCommented:
Sorry

>>editorPane.setContent("text/html");


should have been

editorPane.setContentType("text/html");
0
 
csoundAuthor Commented:
oh... I didn't. It works now thanx. Can I ask one more question please? I've just noticed that the JEditorPane didn't display a table. It displayed information in tabular form but didn't display borders. Whay is this?
0
 
CEHJCommented:
I'm afraid the html support is very limited, so it wouldn't surprise me if table borders were not supported.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now