Skip to content

Commit

Permalink
Added a default case to skip processing instructions, doctypes etc
Browse files Browse the repository at this point in the history
  • Loading branch information
senior committed Feb 9, 2012
1 parent edd0aeb commit 89fe25e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/main/clojure/clojure/data/xml.clj
Expand Up @@ -214,12 +214,10 @@
(cons (event :characters nil nil text)
(pull-seq sreader))
(recur))
XMLStreamConstants/COMMENT
(recur)
XMLStreamConstants/SPACE
(recur)
XMLStreamConstants/END_DOCUMENT
nil))))
nil
(recur);; Consume and ignore comments, spaces, processing instructions etc
))))

(defn source-seq
"Parses the XML InputSource source using a pull-parser. Returns
Expand Down
14 changes: 14 additions & 0 deletions src/test/clojure/clojure/data/xml/test_parse.clj
Expand Up @@ -59,3 +59,17 @@
"there")))]
(is (= expected (lazy-parse* input)))))

(deftest test-parsing-processing-instructions
(let [input "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<?xml-stylesheet type='text/xsl' href='someFile.xsl'?>
<ATag>With Stuff</ATag>"
expected (element :ATag {} "With Stuff")]
(is (= expected (parse-str input)))))

(deftest test-parsing-doctypes
(let [input "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
\"foo://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html><h1>Heading Stuff</h1></html>"
expected (element :html {}
(element :h1 {} "Heading Stuff"))]
(is (= expected (parse-str input)))))

0 comments on commit 89fe25e

Please sign in to comment.