JTidy提供了一個語法檢查器和標籤補償器,能夠對各種亂七八糟的html進行修複,使之符合xhtml標準。
其一些常用的參數設定:
setAltText(java.lang.String altText)
加上預設的alt屬性值
setBreakBeforeBR(boolean breakBeforeBR)
在換行
之前加一空行
setCharEncoding(int charencoding)
已廢棄
setConfigurationFromFile(java.lang.String filename)
從檔案中讀取配置資訊
setConfigurationFromProps(java.util.Properties props)
從properties中讀取配置資訊
setErrfile(java.lang.String errfile)
錯誤輸出檔案
setFixBackslash(boolean fixBackslash)
URL中用/取代/
setForceOutput(boolean forceOutput)
不管產生的xml是否有錯,強制輸出。
setHideComments(boolean hideComments)
結果中不產生注釋
setInputEncoding(java.lang.String encoding)
輸入編碼
setLogicalEmphasis(boolean logicalEmphasis)
用em替代i,strong替代b
setMessageListener(TidyMessageListener listener)
加入一個TidyMessageListener監聽器
setOnlyErrors(boolean onlyErrors)
只輸出錯誤檔案
setOutputEncoding(java.lang.String encoding)
輸出編碼
setPrintBodyOnly(boolean bodyOnly)
只輸出body中的部分
setRepeatedAttributes(int repeatedAttributes)
重複屬性的處理
setSpaces(int spaces)
每行前的空格數,就是縮排格式
setTidyMark(boolean tidyMark)
是否產生tidy標記
setTrimEmptyElements(boolean trimEmpty)
不輸出空元素
setUpperCaseAttrs(boolean upperCaseAttrs)
屬性變大寫
setUpperCaseTags(boolean upperCaseTags)
標記變大寫
setWraplen(int wraplen)
多長換行
setXHTML(boolean xhtml)
輸出xhtml
setXmlOut(boolean xmlOut)
輸出xml
setXmlPi(boolean xmlPi)
檔案頭輸出xml標記
setXmlSpace(boolean xmlSpace)
加入xml名字空間屬性