|
38 | 38 | name/uri-file name/print-uri-file-command! |
39 | 39 | process/find-xmlns process/aggregate-xmlns) |
40 | 40 |
|
| 41 | +(def ^:private ^:const parser-opts-arg |
| 42 | + '{:keys [include-node? location-info |
| 43 | + coalescing supporting-external-entities |
| 44 | + allocator namespace-aware replacing-entity-references |
| 45 | + validating reporter resolver support-dtd] |
| 46 | + :or {include-node? #{:element :characters} |
| 47 | + location-info true |
| 48 | + coalescing true |
| 49 | + supporting-external-entities false}}) |
| 50 | + |
41 | 51 | (defn event-seq |
42 | | - "Parses the XML InputSource source using a pull-parser. Returns |
43 | | - a lazy sequence of Event records. Accepts key pairs |
44 | | - with XMLInputFactory options, see http://docs.oracle.com/javase/6/docs/api/javax/xml/stream/XMLInputFactory.html |
45 | | - and xml-input-factory-props for more information. |
46 | | - Defaults coalescing true and supporting-external-entities false. |
47 | | - :include-node? can be a set of #{:start-element :end-element :characters :comment}" |
48 | | - [source {:as props}] |
| 52 | + "Parses an XML input source into a lazy sequence of pull events. |
| 53 | +
|
| 54 | +Input source can be a java.io.InputStream or java.io.Reader |
| 55 | +
|
| 56 | +Options: |
| 57 | +
|
| 58 | + :include-node? can be a subset of #{:element :characters :comment} default #{:element :characters} |
| 59 | + :location-info pass false to skip generating location meta data |
| 60 | +
|
| 61 | +See http://docs.oracle.com/javase/6/docs/api/javax/xml/stream/XMLInputFactory.html |
| 62 | +for documentation on options: |
| 63 | +
|
| 64 | + {:allocator XMLInputFactory/ALLOCATOR |
| 65 | + :coalescing XMLInputFactory/IS_COALESCING |
| 66 | + :namespace-aware XMLInputFactory/IS_NAMESPACE_AWARE |
| 67 | + :replacing-entity-references XMLInputFactory/IS_REPLACING_ENTITY_REFERENCES |
| 68 | + :supporting-external-entities XMLInputFactory/IS_SUPPORTING_EXTERNAL_ENTITIES |
| 69 | + :validating XMLInputFactory/IS_VALIDATING |
| 70 | + :reporter XMLInputFactory/REPORTER |
| 71 | + :resolver XMLInputFactory/RESOLVER |
| 72 | + :support-dtd XMLInputFactory/SUPPORT_DTD}" |
| 73 | + {:arglists (list ['source parser-opts-arg])} |
| 74 | + [source opts] |
49 | 75 | (let [props* (merge {:include-node? #{:element :characters} |
50 | 76 | :coalescing true |
51 | 77 | :supporting-external-entities false |
52 | 78 | :location-info true} |
53 | | - props)] |
| 79 | + opts)] |
54 | 80 | (pull-seq (make-stream-reader props* source) |
55 | 81 | props* |
56 | 82 | nil))) |
57 | 83 |
|
58 | 84 | (defn parse |
59 | | - "Parses the source, which can be an |
60 | | - InputStream or Reader, and returns a lazy tree of Element records. Accepts key pairs |
61 | | - with XMLInputFactory options, see http://docs.oracle.com/javase/6/docs/api/javax/xml/stream/XMLInputFactory.html |
62 | | - and xml-input-factory-props for more information. Defaults coalescing true." |
63 | | - [source & opts] |
| 85 | + "Parses an XML input source into a a tree of Element records. |
| 86 | +The element tree is realized lazily, so huge XML files can be streamed through a depth-first tree walk. |
| 87 | +
|
| 88 | +Input source can be a java.io.InputStream or java.io.Reader |
| 89 | +
|
| 90 | +Options: |
| 91 | +
|
| 92 | + :include-node? can be a subset of #{:element :characters :comment} default #{:element :characters} |
| 93 | + :location-info pass false to skip generating location meta data |
| 94 | +
|
| 95 | +See http://docs.oracle.com/javase/6/docs/api/javax/xml/stream/XMLInputFactory.html |
| 96 | +for documentation on options: |
| 97 | +
|
| 98 | + {:allocator XMLInputFactory/ALLOCATOR |
| 99 | + :coalescing XMLInputFactory/IS_COALESCING |
| 100 | + :namespace-aware XMLInputFactory/IS_NAMESPACE_AWARE |
| 101 | + :replacing-entity-references XMLInputFactory/IS_REPLACING_ENTITY_REFERENCES |
| 102 | + :supporting-external-entities XMLInputFactory/IS_SUPPORTING_EXTERNAL_ENTITIES |
| 103 | + :validating XMLInputFactory/IS_VALIDATING |
| 104 | + :reporter XMLInputFactory/REPORTER |
| 105 | + :resolver XMLInputFactory/RESOLVER |
| 106 | + :support-dtd XMLInputFactory/SUPPORT_DTD}" |
| 107 | + {:arglists (list ['source '& parser-opts-arg])} |
| 108 | + [source & {:as opts}] |
64 | 109 | (event-tree (event-seq source opts))) |
65 | 110 |
|
66 | 111 | (defn parse-str |
67 | | - "Parses the passed in string to Clojure data structures. Accepts key pairs |
68 | | - with XMLInputFactory options, see http://docs.oracle.com/javase/6/docs/api/javax/xml/stream/XMLInputFactory.html |
69 | | - and xml-input-factory-props for more information. Defaults coalescing true." |
| 112 | + "Parses an XML String into a a tree of Element records. |
| 113 | +
|
| 114 | +Options: |
| 115 | +
|
| 116 | + :include-node? can be a subset of #{:element :characters :comment} default #{:element :characters} |
| 117 | + :location-info pass false to skip generating location meta data |
| 118 | +
|
| 119 | +See http://docs.oracle.com/javase/6/docs/api/javax/xml/stream/XMLInputFactory.html |
| 120 | +for documentation on options: |
| 121 | +
|
| 122 | + {:allocator XMLInputFactory/ALLOCATOR |
| 123 | + :coalescing XMLInputFactory/IS_COALESCING |
| 124 | + :namespace-aware XMLInputFactory/IS_NAMESPACE_AWARE |
| 125 | + :replacing-entity-references XMLInputFactory/IS_REPLACING_ENTITY_REFERENCES |
| 126 | + :supporting-external-entities XMLInputFactory/IS_SUPPORTING_EXTERNAL_ENTITIES |
| 127 | + :validating XMLInputFactory/IS_VALIDATING |
| 128 | + :reporter XMLInputFactory/REPORTER |
| 129 | + :resolver XMLInputFactory/RESOLVER |
| 130 | + :support-dtd XMLInputFactory/SUPPORT_DTD}" |
| 131 | + {:arglists (list ['string '& parser-opts-arg])} |
70 | 132 | [s & opts] |
71 | 133 | (apply parse (string-source s) opts)) |
72 | 134 |
|
|
0 commit comments