Permalink
Browse files

Added a default case to skip processing instructions, doctypes etc

  • Loading branch information...
senior committed Feb 9, 2012
1 parent edd0aeb commit 89fe25e8f4c577c5d5b50a4ffcaf0627ea81c350
Showing with 17 additions and 5 deletions.
  1. +3 −5 src/main/clojure/clojure/data/xml.clj
  2. +14 −0 src/test/clojure/clojure/data/xml/test_parse.clj
@@ -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
@@ -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.