Mark Volkmann a écrit : > On Wed, Feb 18, 2009 at 7:40 AM, Christophe Grand <christo...@cgrand.net> > wrote: > >> Remco van 't Veer a écrit : >> >>> Maybe *ignore-whitespace* is a beter name since it doesn't remove >>> anything and will retain some of it. I would prefer it to default to >>> true. >>> >>> >> I would prefer it to default to false since it's the standard way to >> handle whitespace in XML. (Ignorable whitespaces are always ignored by >> clojure.xml.) >> > > I agree. That would be consistent with Apache Xerces which also uses > that term and retains all whitespace by default. >
Patch attached. Mark, by "all whitespace" do you mean all significant whitespaces or really all whitespaces (including ignorable whitespaces)? -- 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..0dfae98 100644 --- a/src/clj/clojure/xml.clj +++ b/src/clj/clojure/xml.clj @@ -10,6 +10,9 @@ (:import (org.xml.sax ContentHandler Attributes SAXException) (javax.xml.parsers SAXParser SAXParserFactory))) +(def #^{:doc "When set to true clojure.xml/parse ignores significant whitespace."} + *ignore-whitespace* false) + (def *stack*) (def *current*) (def *state*) ; :element :chars :between @@ -25,8 +28,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) + (not (and *ignore-whitespace* + (every? #(. Character (isWhitespace %)) (str *sb*))))) (set! *current* (push-content *current* (str *sb*)))))] (new clojure.lang.XMLHandler (proxy [ContentHandler] []