HTML文档解析器 NekoHTML

jopen 12年前
     <p>NekoHTML是一个Java语言的 HTML扫描器和标签补全器(tag balancer) ,使得程序能解析HTML文档并用标准的XML接口来访问其中的信息。这个解析器能够扫描HTML文件并“修正”许多作者(人或机器)在编写HTML文档 过程中常犯的错误。</p>    <p>NekoHTML能增补缺失的父元素、自动用结束标签关闭相应的元素,以及不匹配的内嵌元素标签。NekoHTML的开发使用了 Xerces Native Interface (XNI),后者是Xerces2的实现基础。</p>    <p>示例代码:</p>    <pre class="brush:html; toolbar: true; auto-links: false;">package sample;  import org.cyberneko.html.parsers.DOMParser; import org.w3c.dom.Document; import org.w3c.dom.Node;  public class TestHTMLDOM {     public static void main(String[] argv) throws Exception {         DOMParser parser = new DOMParser();         for (int i = 0; i < argv.length; i++) {             parser.parse(argv[i]);             print(parser.getDocument(), "");         }     }     public static void print(Node node, String indent) {         System.out.println(indent+node.getClass().getName());         Node child = node.getFirstChild();         while (child != null) {             print(child, indent+" ");             child = child.getNextSibling();         }     } }</pre>    <p><strong>项目主页:</strong><a href="http://www.open-open.com/lib/view/home/1324372332155" target="_blank">http://www.open-open.com/lib/view/home/1324372332155</a></p>    <p></p>