|
91 | 91 | (string? el) (text-node el) |
92 | 92 | (instance? Element el) el |
93 | 93 | ;; stupid xmldom, (some? (.-item el)) |
94 | | - (instance? NodeList el) el |
| 94 | + #_(instance? NodeList el) |
| 95 | + (some? (.-item el)) el |
95 | 96 | (instance? Text el) el |
96 | 97 | (satisfies? ILookup el) (element* (:tag el) |
97 | 98 | (:attrs el) |
|
110 | 111 | (identical? xmlns-uri (.-namespaceURI a))) |
111 | 112 | (def remove-xmlns-attrs-xf (remove xmlns-attr?)) |
112 | 113 | (def remove-xmlns-attrs (partial into {} remove-xmlns-attrs-xf)) |
113 | | -(def filter-xmlns-attrs (partial into {} (filter xmlns-attr?))) |
| 114 | +(def filter-xmlns-attrs-xf (filter xmlns-attr?)) |
| 115 | +(def filter-xmlns-attrs (partial into {} filter-xmlns-attrs-xf)) |
114 | 116 |
|
115 | | -(defn dom-element-attrs [el] |
116 | | - (transduce |
117 | | - remove-xmlns-attrs-xf |
118 | | - (completing |
119 | | - (fn [ta attr-node] |
120 | | - (assoc! ta |
121 | | - (dom-element-tag attr-node) |
122 | | - (.-value attr-node))) |
123 | | - persistent!) |
124 | | - (transient {}) |
125 | | - (array-seq el))) |
| 117 | +(defn dom-element-attrs |
| 118 | + ([el] (dom-element-attrs remove-xmlns-attrs-xf el)) |
| 119 | + ([xf el] |
| 120 | + (transduce |
| 121 | + xf |
| 122 | + (completing |
| 123 | + (fn [ta attr-node] |
| 124 | + (assoc! ta |
| 125 | + (dom-element-tag attr-node) |
| 126 | + (.-value attr-node))) |
| 127 | + persistent!) |
| 128 | + (transient {}) |
| 129 | + (array-seq el)))) |
126 | 130 |
|
127 | 131 | (declare element-data) |
128 | 132 |
|
129 | 133 | (defn- node-list-vec [nl] |
130 | | - (mapv element-data (array-seq nl))) |
| 134 | + (into [] (map element-data) (array-seq nl))) |
131 | 135 |
|
132 | 136 | (defn- as-node [n] |
133 | 137 | (if (instance? Text n) |
|
144 | 148 | (node/element* (dom-element-tag el) |
145 | 149 | (dom-element-attrs (.-attributes el)) |
146 | 150 | (node-list-vec (.-childNodes el)) |
147 | | - (do |
148 | | - (prn "META" {:clojure.data.xml/nss (filter-xmlns-attrs |
149 | | - (.-attributes el))}) |
150 | | - {:clojure.data.xml/nss (filter-xmlns-attrs |
151 | | - (.-attributes el))})) |
| 151 | + {:clojure.data.xml/nss (dom-element-attrs |
| 152 | + filter-xmlns-attrs-xf |
| 153 | + (.-attributes el))}) |
152 | 154 | ;;(instance? NamedNodeMap el) |
153 | 155 | (.-getNamedItemNS el) |
154 | 156 | (dom-element-attrs el) |
|
174 | 176 | :content (.-childNodes el) |
175 | 177 | (throw "XML tag has no key" {:key k :el el}))) |
176 | 178 | ([el k nf] |
177 | | - (println "Element" k "=>" (case k |
178 | | - :tag (dom-element-tag el) |
179 | | - :attrs (.-attributes el) |
180 | | - :content (.-childNodes el) |
181 | | - nf)) |
| 179 | + #_(println "Element" k "=>" (case k |
| 180 | + :tag (dom-element-tag el) |
| 181 | + :attrs (.-attributes el) |
| 182 | + :content (.-childNodes el) |
| 183 | + nf)) |
182 | 184 | (case k |
183 | 185 | :tag (dom-element-tag el) |
184 | 186 | :attrs (remove-xmlns-attrs (.-attributes el)) |
|
208 | 210 | (.-value i) |
209 | 211 | nil)) |
210 | 212 | ([attrs attr not-found] |
211 | | - (println "Attrs" attr "=>" (if-let [i (.getNamedItemNS attrs (qname-uri attr) (qname-local attr))] |
212 | | - (.-value i) |
213 | | - not-found)) |
| 213 | + #_(println "Attrs" attr "=>" (if-let [i (.getNamedItemNS attrs (qname-uri attr) (qname-local attr))] |
| 214 | + (.-value i) |
| 215 | + not-found)) |
214 | 216 | (if-let [i (.getNamedItemNS attrs (qname-uri attr) (qname-local attr))] |
215 | 217 | (.-value i) |
216 | 218 | not-found))) |
|
229 | 231 | init nm)) |
230 | 232 | IEquiv |
231 | 233 | (-equiv [nm0 nm1] |
232 | | - (println "NamedNodeMap.-equiv" (identical? nm0 nm1) (count nm0) (count nm1)) |
| 234 | + #_(println "NamedNodeMap.-equiv" (identical? nm0 nm1) (count nm0) (count nm1)) |
233 | 235 | (or (identical? nm0 nm1) |
234 | 236 | (and (identical? (count nm0) (count nm1)) |
235 | 237 | (reduce-kv (fn [_ qn v] |
236 | | - (println "=" v 'qn qn '(get nm1 qn "") (get nm1 qn "")) |
| 238 | + #_(println "=" v 'qn qn '(get nm1 qn "") (get nm1 qn "")) |
237 | 239 | (or (identical? v (get nm1 qn "")) |
238 | 240 | (reduced false))) |
239 | 241 | true nm0))))) |
|
254 | 256 | nf))) |
255 | 257 | IEquiv |
256 | 258 | (-equiv [nl0 nl1] |
257 | | - (println "NodeList.-equiv") |
| 259 | + #_(println "NodeList.-equiv") |
258 | 260 | (or (identical? nl0 nl1) |
259 | 261 | (and (identical? (count nl0) (count nl1)) |
260 | 262 | (reduce (fn [_ n] |
|
0 commit comments