0

clojure-xml/parse returns a map of an xml file.

(ns xml-lib.core
  ^{:author "Charles M. Norton",
    :doc "xml-lib is an xml parsing library built on clojure-xml.
        Created on June 26, 2012"} 
  (:require [clojure.string :as cstr])
  (:require [util.core :as utl])
  (:require [clojure.xml :as cjxml]))

(defn ret-xml-data
    "Returns a map of the supplied xml file."
    [xml-fnam]

    (let [test-file-nam (utl/open xml-fnam)]
    (cjxml/parse xml-fnam))

Is the returned map lazy, or should I pass the parse call into a lazy sequence function?

Thanks.

(ret-xml-data "test.xml")

returns (result truncated).

{:tag :TamperExport, :attrs {:xmlns "http://
1
  • If you want to parse XML with Clojure lazily, I'd recommend clojure.data.xml, which is the successor to what used to be in clojure-xml from clojure-contrib. Commented Apr 30, 2013 at 17:55

2 Answers 2

3

the short anser is no, clojure-xml likely won't do what you want.

data.xml is the lazy sucessor to clojure-xml

https://github.com/clojure/data.xml

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. I'll go look at that tomorrow.
This is useful, but it is a comment, not an answer to the question (which is "no", by the way). It could be rephrased to be an answer (nudge, nudge).
1

It uses a SAX Parser under the hood, which will consume the entire xml document, so I assume that it will create the fully realized data structure.

3 Comments

Which means I should make it lazy? I'm assuming that because you used the phrase "fully realized". Thanks.
I mean that it is a complete data structure, so it's already there - in memory; all of it.
SAX parser doesn't necessarily mean it creates a fully realized data structure, though in this case that's correct. The old contrib.lazy-xml started the parser in a new thread which put elements into a queue, and returned a seq that pulled elements off the queue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.