我如何懒惰地解析Clojure中的大XHTML文件?

Jir*_*esl 11 xhtml parsing clojure html-parsing

我有一个大表的有效XHTML文件(100兆字节的数据).第一个tr是列(用于数据库),所有其他tr是数据.它是整个文档中唯一的表,它在结构html-> body-> div-> table中.

我如何在Clojure中解析它懒惰的方式?

我知道data.xml,但因为我是Clj初学者,所以我很难让它工作.特别是因为REPL在处理如此大的文件时非常慢.

Nik*_*zov 15

data.xmldocs说它创建了一个文档的懒树:解析.我在当地检查过它似乎是真的:

; Load libs
(require '[clojure.data.xml :as xml])
(require '[clojure.java.io :as io])

; standard.xml is 100MB xml file from here http://www.xml-benchmark.org/downloads.html
(def xml-tree (xml/parse (io/reader "standard.xml")))
(:tag xml-tree) => :site

(def child (first (:content xml-tree)))
(:tag child) => :regions

(dorun (:content xml-tree)) => REPL hangs for ~30 seconds on my computer because it tries to parse whole file
Run Code Online (Sandbox Code Playgroud)