Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 63c610b1857b837b63acc514665b8c7e3f0b20cd 1 parent 620b21f
@senior senior authored
View
7 src/main/clojure/clojure/data/xml.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]
View
18 src/test/clojure/clojure/data/xml/test_sexp.clj
@@ -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

@AlexBaranosky

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.

@senior
Collaborator

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

@senior
Collaborator

0.0.7 has been released

@AlexBaranosky
Please sign in to comment.
Something went wrong with that request. Please try again.