Programmatic HTMLDocument generation using Java

前端 未结 9 1885
孤独总比滥情好
孤独总比滥情好 2021-02-14 03:34

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

9条回答
  •  暖寄归人
    2021-02-14 04:17

    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.

提交回复
热议问题