Hello, Currently clojure.xml discards text nodes when they contain only whitespace characters. Can this behavior be made optional? Attached is a patch which adds a *preserve-whitespace* var (by defaul to false).
Thanks, Christophe -- Professional: http://cgrand.net/ (fr) On Clojure: http://clj-me.blogspot.com/ (en) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---
diff --git a/src/clj/clojure/xml.clj b/src/clj/clojure/xml.clj index 251f16c..15f3ade 100644 --- a/src/clj/clojure/xml.clj +++ b/src/clj/clojure/xml.clj @@ -14,6 +14,8 @@ (def *current*) (def *state*) ; :element :chars :between (def *sb*) +(def #^{:doc "When set to true, clojure.xml/parse preserves significant whitespace."} + *preserve-whitespace* false) (defstruct element :tag :attrs :content) @@ -25,8 +27,9 @@ (let [push-content (fn [e c] (assoc e :content (conj (or (:content e) []) c))) push-chars (fn [] - (when (and (= *state* :chars) - (some (complement #(. Character (isWhitespace %))) (str *sb*))) + (when (and (= *state* :chars) + (or *preserve-whitespace* + (some (complement #(. Character (isWhitespace %))) (str *sb*)))) (set! *current* (push-content *current* (str *sb*)))))] (new clojure.lang.XMLHandler (proxy [ContentHandler] []