Permalink
Browse files

Added some comments/docs on the keyword input parsing parameters

  • Loading branch information...
1 parent 1cf6cf8 commit 5671774c5013f13fea3410be6e461a5f4956a7f5 @senior senior committed Mar 14, 2012
Showing with 15 additions and 6 deletions.
  1. +5 −1 README.md
  2. +10 −5 src/main/clojure/clojure/data/xml.clj
View
@@ -69,8 +69,12 @@ or
:content ("The baz value")})})}
The data is returned as defrecords and can be manipulated using the
-normal clojure data structure functions.
+normal clojure data structure functions. Additional parsing options
+can be passed via key pairs:
+ (parse-str "<a><![CDATA[\nfoo bar\n]]><![CDATA[\nbaz\n]]></a>" :coalescing false)
+ #clojure.data.xml.Element{:tag :a, :attrs {}, :content ("\nfoo bar\n" "\nbaz\n")}
+
XML elements can be created using the typical defrecord constructor
functions or the element function used below, and written using a
[java.io.Writer](http://docs.oracle.com/javase/6/docs/api/java/io/Writer.html).:
@@ -239,21 +239,26 @@
(defn source-seq
"Parses the XML InputSource source using a pull-parser. Returns
- a lazy sequence of Event records."
+ a lazy sequence of Event records. Accepts key pairs
+ with XMLInputFactory options, see http://docs.oracle.com/javase/6/docs/api/javax/xml/stream/XMLInputFactory.html
+ and xml-input-factory-props for more information. Defaults coalescing true."
[s & {:as props}]
(let [fac (new-xml-input-factory (merge {:coalescing true} props))
sreader (.createXMLStreamReader fac s)]
(pull-seq sreader)))
(defn parse
- "Convenience function. Parses the source, which can be an
- InputStream or Reader, and returns a lazy tree of Element records.
- See lazy-source-seq for finer-grained control."
+ "Parses the source, which can be an
+ InputStream or Reader, and returns a lazy tree of Element records. Accepts key pairs
+ with XMLInputFactory options, see http://docs.oracle.com/javase/6/docs/api/javax/xml/stream/XMLInputFactory.html
+ and xml-input-factory-props for more information. Defaults coalescing true."
[source & props]
(event-tree (apply source-seq source props)))
(defn parse-str
- "Parses the passed in string to Clojure data structures"
+ "Parses the passed in string to Clojure data structures. Accepts key pairs
+ with XMLInputFactory options, see http://docs.oracle.com/javase/6/docs/api/javax/xml/stream/XMLInputFactory.html
+ and xml-input-factory-props for more information. Defaults coalescing true."
[s & props]
(let [sr (java.io.StringReader. s)]
(apply parse sr props)))

0 comments on commit 5671774

Please sign in to comment.