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://
octopusgrabbus
  • 10,555
  • 15
  • 68
  • 131
  • If you want to parse XML with Clojure lazily, I'd recommend [clojure.data.xml](https://github.com/clojure/data.xml), which is the successor to what used to be in clojure-xml from clojure-contrib. – David J. Apr 30 '13 at 17:55

2 Answers2

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

Arthur Ulfeldt
  • 90,827
  • 27
  • 201
  • 284
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.

BillRobertson42
  • 12,602
  • 4
  • 40
  • 57
  • Which means I should make it lazy? I'm assuming that because you used the phrase "fully realized". Thanks. – octopusgrabbus Jun 26 '12 at 19:20
  • I mean that it is a complete data structure, so it's already there - in memory; all of it. – BillRobertson42 Jun 26 '12 at 20:41
  • 2
    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. – Alex Jun 26 '12 at 21:09