Permalink
Browse files

Fix to ignore whitespace parsing events

  • Loading branch information...
1 parent c9fd2f4 commit 1b4d2873b79d8bc2ac45576f12aa70c602837e06 @senior senior committed Jan 16, 2012
Showing with 14 additions and 4 deletions.
  1. +1 −1 pom.xml
  2. +4 −2 src/main/clojure/clojure/data/xml.clj
  3. +9 −1 src/test/clojure/clojure/data/xml/test_parse.clj
View
@@ -3,7 +3,7 @@
<artifactId>data.xml</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>data.xml</name>
- <packaging>pom</packaging>
+ <packaging>jar</packaging>
<description>Functions to parse XML into lazy sequences and lazy trees and emit these as text</description>
<developers>
@@ -213,9 +213,11 @@
(keyword (.getLocalName sreader)) nil nil)
(pull-seq sreader))
XMLStreamConstants/CHARACTERS
- (let [text (.getText sreader)]
+ (if-let [text (and (not (.isWhiteSpace sreader))
+ (.getText sreader))]
(cons (event :characters nil nil text)
- (pull-seq sreader)))
+ (pull-seq sreader))
+ (pull-seq sreader))
XMLStreamConstants/COMMENT
(pull-seq sreader)
@@ -37,12 +37,19 @@
" t12" (element :g {} "t13") "t14")]
(is (= expected (lazy-parse* input)))))
+(deftest test-xml-with-whitespace
+ (let [input (str "<a>\n<b with-attr=\"s p a c e\">123</b>\n<c>1 2 3</c>\n\n</a>")
+ expected (element :a {}
+ (element :b {:with-attr "s p a c e"} "123")
+ (element :c {} "1 2 3"))]
+ (is (= expected (lazy-parse* input)))))
+
(deftest test-cdata-parse
(let [input "<cdata><is><here><![CDATA[<dont><parse><me>]]></here></is></cdata>"
expected (element :cdata {} (element :is {}
(element :here {}
"<dont><parse><me>")))]
- (is (= expected (lazy-parse* input)))) )
+ (is (= expected (lazy-parse* input)))))
(deftest test-comment-parse
(let [input "<comment><is><here><!-- or could be -->there</here></is></comment>"
@@ -63,3 +70,4 @@
(reset! event1 nil)
(System/gc)
(is (= nil (.get weak))))))))
+

0 comments on commit 1b4d287

Please sign in to comment.