4
我很難與我的NekoHTML解析器。 它在URL上工作正常,但是當我想測試一個簡單的XML測試時,它不會正確讀取它。Groovy - NekoHTML Sax解析器
這是我如何把它聲明:
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.
}
當我再次使用它的網站上這是工作非常精細。 任何猜測爲什麼我不能這樣做簡單的XML文本樣本?
任何幫助非常apreciated :)
失敗時它有什麼作用?有沒有堆棧跟蹤?什麼是它失敗的XML文檔的例子?請提供更多信息。 –
抱歉回答這麼晚了,謝謝你的回答。 解析不會崩潰,也不會寫入堆棧跟蹤。 這只是不正確解析。 例如,如果我給下面的示例: 臥室 廚房 文件的路徑(路徑相當於文檔節點的)實際上是文本「臥室」 ... 因此,我的問題是這,它不正確地初始化解析,阻止我做我想做的事。 如果你有什麼想法可能是錯誤的......我在聽:) –