使用SAX解析器解析html [英] Parsing html with SAX parser

查看:207
本文介绍了使用SAX解析器解析html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用SAX解析器解析普通的html文件。

I am trying to parse the normal html file using SAX parser.

SAXBuilder builder2 = new SAXBuilder();
         try {
            Document sdoc = (Document)builder2.build(readFile);
            NodeList nl=sdoc.getElementsByTagName("body");
            System.out.println("nodelist>>>>>>>>>>>"+nl.getLength());

        } catch (JDOMException e1) {
            e1.printStackTrace();
        }

但是我得到了例外

Open quote is expected for attribute "{1}" associated with an  element type  "class".

任何人都可以告诉我为什么我得到这个例外,html文件格式正确且它有所有打开和关闭的标签都正确。

can anyone please tell me why i am getting this exception, the html document is well formed and it has all the open and close tags properly.

提前致谢。

推荐答案

正如flash所说,你需要一个HTML解析器,而不是XML解析器。 HTML不是XML。

As flash says, you need an HTML parser, not an XML parser. HTML is not XML.

我使用的好解析器是 Neko TagSoup 。 Neko是一个很好的全面解析器; TagSoup专门用于解析任何内容,无论形式多么糟糕。

Good parsers i've used are Neko and TagSoup. Neko is a good all-round parser; TagSoup specifically aims to be able to parse anything, no matter how ill-formed.

这篇关于使用SAX解析器解析html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆