Groovy – NekoHTML Sax解析器
发布时间:2020-12-14 16:21:49 所属栏目:大数据 来源:网络整理
导读:我很难用我的Neko HTML解析器. 它在URL上工作正常,但是当我想在一个简单的 XML测试中进行测试时,它没有正确读取它. 以下是我的声明: def createAndSetParser() { SAXParser parser = new SAXParser() //Default Sax NekoHTML parser def charset = "Windows
|
我很难用我的Neko
HTML解析器.
它在URL上工作正常,但是当我想在一个简单的 XML测试中进行测试时,它没有正确读取它. 以下是我的声明: def createAndSetParser() {
SAXParser parser = new SAXParser() //Default Sax NekoHTML parser
def charset = "Windows-1252" // The encoding of the page
def tagFormat = "upper" // Ensures all the tags and consistently written,by putting all of them in upper-case. We can choose "lower","upper" of "match"
def attrFormat = "lower" // Same thing for attributes. We can choose "upper","lower" or "match"
Purifier purifier = new Purifier() //Creating a purifier,in order to clean the incoming HTML
XMLDocumentFilter[] filter = [purifier] //Creating a filter,and adding the purifier to this filter. (NekoHTML feature)
parser.setProperty("http://cyberneko.org/html/properties/filters",filter)
parser.setProperty("http://cyberneko.org/html/properties/default-encoding",charset)
parser.setProperty("http://cyberneko.org/html/properties/names/elems",tagFormat)
parser.setProperty("http://cyberneko.org/html/properties/names/attrs",attrFormat)
parser.setFeature("http://cyberneko.org/html/features/scanner/ignore-specified-charset",true) // Forces the parser to use the charset we provided to him.
parser.setFeature("http://cyberneko.org/html/features/override-doctype",false) // To let the Doctype as it is.
parser.setFeature("http://cyberneko.org/html/features/override-namespaces",false) // To make sure no namespace is added or overridden.
parser.setFeature("http://cyberneko.org/html/features/balance-tags",true)
return new XmlSlurper(parser) // A groovy parser that does not download the all tree structure,but rather supply only the information it is asked for.
}
当我在网站上使用它时,它再次工作得非常好. 任何帮助大大apreciated (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
