Documentation for data.xml/parse says
The data is returned as defrecords and can be manipulated using the normal clojure data structure functions.
Can the structure of those defrecords be inferred manually or programmatically, and, if so, how?
Here is the example in the docs compacted somewhat:
(let [input-xml (java.io.StringReader.
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<foo><bar><baz>The baz value</baz></bar></foo>")]
(parse input-xml))
#clojure.data.xml.Element{:tag :foo,
:attrs {},
:content
(
#clojure.data.xml.Element{:tag :bar,
:attrs {},
:content (#clojure.data.xml.Element{:tag :baz,
:attrs {},
:content ("The baz value")})})}
In general, defrecords can be operated on as maps, because that is essentially what they are.
For example:
Now, we have defined a defrecord type, a Dog.
So clearly, the “keys” function, which we all know and love for operating on maps, works fine.
But to take it further, we find that a defrecord, alas, is truly a map :
So — why all this fuss over a simple map ? Because, since xml has a well-defined structure, it makes sense that we can have some gauranteed keys in every defrecord returned. In particular, the defrecord elements ill each have “:tag, :attrs, and :content”. To confirm, you can note thatthese constant defrecord attributes are always present in the online tutorials of parsing xml with clojure (i.e. http://www.gettingclojure.com/cookbook:xml-html ).