我正在使用jtidy-r938.jar。当一个列表项不包含文本但后跟另一个列表时,解析失败,错误为“error:panic-tree has lost its integrity”。
测试
1
2
下面是示例代码
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Properties;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.tidy.Tidy;
public class TestJTidy
{
private final static Tidy tidy = new Tidy();
public static void main(String[] args) throws UnsupportedEncodingException
{
TestJTidy t = new TestJTidy();
t.setup();
String rawXHTML = "<ol><li>Test<ol><li>1</li></ol><ol><li><ol><li>2</li></ol></li></ol></li></ol>";
rawXHTML = rawXHTML.replaceAll("\t", " "); //$NON-NLS-1$ //$NON-NLS-2$
ByteArrayInputStream bais = new ByteArrayInputStream(rawXHTML.getBytes("UTF-8"));
Document doc = tidy.parseDOM(bais, null);
NodeList bodyList = doc.getElementsByTagName("body"); //$NON-NLS-1$
System.out.println("done");
}
private void setup()
{
InputStream is = null;
try
{
is = this.getClass().getResourceAsStream("tidy-config.cfg"); //$NON-NLS-1$
Properties props = new Properties();
props.load(is);
tidy.setConfigurationFromProps(props);
}
catch (IOException ignored)
{
// ignore
}
finally
{
try
{
if (is != null)
{
is.close();
}
}
catch (Exception ignored)
{
}
}
}
}
任何帮助我了解如何解决这个问题将不胜感激。
谢谢
暂无答案!
目前还没有任何答案,快来回答吧!