Permalink
Browse files

added cdata support for sexp-as-element (DXML-11)

  • Loading branch information...
1 parent 620b21f commit 63c610b1857b837b63acc514665b8c7e3f0b20cd @senior senior committed Dec 12, 2012
Showing with 24 additions and 1 deletion.
  1. +6 −1 src/main/clojure/clojure/data/xml.clj
  2. +18 −0 src/test/clojure/clojure/data/xml/test_sexp.clj
@@ -178,6 +178,11 @@
(defprotocol AsElements
(as-elements [expr] "Return a seq of elements represented by an expression."))
+(defn sexp-element [tag attrs child]
+ (cond
+ (= :-cdata tag) (CData. (first child))
+ :else (Element. tag attrs (mapcat as-elements child))))
+
(extend-protocol AsElements
clojure.lang.IPersistentVector
(as-elements [v]
@@ -187,7 +192,7 @@
[k (str v)]))
after-attrs]
[{} content])]
- [(Element. tag attrs (mapcat as-elements content))]))
+ [(sexp-element tag attrs content)]))
clojure.lang.ISeq
(as-elements [s]
@@ -25,3 +25,21 @@
(is (= (sexps-as-fragment input)
(map sexp-as-element input)))
(is (thrown? Exception (sexp-as-element input)))))
+
+(deftest with-cdata
+ (let [xml-input (element :tag {:attr "value"}
+ (element :body {} (cdata "not parsed <stuff")))
+ sexp-input [:tag {:attr "value"} [:body {} [:-cdata "not parsed <stuff"]]]]
+ (is (= xml-input
+ (sexp-as-element sexp-input)))))
+
+(deftest with-multiple-cdata
+ (let [xml-input (element :tag {:attr "value"}
+ (element :body {}
+ (cdata "not parsed <stuff")
+ (cdata "more not parsed <stuff")))
+ sexp-input [:tag {:attr "value"} [:body {}
+ (list [:-cdata "not parsed <stuff"]
+ [:-cdata "more not parsed <stuff"])]]]
+ (is (= xml-input
+ (sexp-as-element sexp-input)))))

4 comments on commit 63c610b

Are these changes not included in 0.0.6? I think I just spent an hour trying to understand why my cdata's weren't parsing as I hoped. :)

What are the chances we could get a release of 0.0.7 soon? We need this functionality at work. What can I do to move it along? I have signed a CA.

Member

senior replied Jan 8, 2013

They are not. I'll get 0.0.7 released today and let you know when it's out there.

Member

senior replied Jan 9, 2013

0.0.7 has been released

Please sign in to comment.