Skip to content

Commit

Permalink
added cdata support for sexp-as-element (DXML-11)
Browse files Browse the repository at this point in the history
  • Loading branch information
senior committed Dec 12, 2012
1 parent 620b21f commit 63c610b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/clojure/clojure/data/xml.clj
Expand Up @@ -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]
Expand All @@ -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]
Expand Down
18 changes: 18 additions & 0 deletions src/test/clojure/clojure/data/xml/test_sexp.clj
Expand Up @@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member Author

@senior senior commented on 63c610b Jan 8, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@senior
Copy link
Member Author

@senior senior commented on 63c610b Jan 9, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.0.7 has been released

@AlexBaranosky
Copy link

@AlexBaranosky AlexBaranosky commented on 63c610b Jan 9, 2013 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.