Does anyone know how to generate an HTMLDocument object programmatically in Java without resorting to generating a String externally and then using HTMLEditorKit#read to parse i
javax.swing.text.html has HTMLWriter
and HTMLDocument
class among others. I have not used them. I have used the HtmlWriter
in .Net and it does exactly what you want, but the java version may not work out to be the same.
Here is the doc: http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/text/html/HTMLWriter.html
Also, I can't imagine a StringBuilder
being slower than building with an object layer. It seems to me that any object oriented approach would have to build the object graph AND then produce the string. The main reason not to use raw strings for this stuff is that you are sure to get encoding errors as well as other mistakes that produce malformed documents.
Option 2: You could use your favorite XML api's and produce XHTML.