JTidy 错误:恐慌 - 树失去了完整性,当没有文本的列表项有另一个列表时

问题描述

我正在使用 jtidy-r938.jar。 当列表项不包含文本但后跟另一个列表时,解析失败并显示错误错误:恐慌 - 树已失去完整性”。

  1. 测试
    1. 1
      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)
            {
            }
        }
    }
}

如果能帮助我理解如何解决这个问题,我们将不胜感激。

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)