Trouble creating xml strings in Clojure

fullprogramas

New Member
I am a Clojure n00b trying to create some XML strings. My goal is to create something like this:\[code\]<?xml version="1.0" encoding="UTF-8"?><items> <item name="n0">n0 value</item> <item name="n1">n1 value</item> <item name="n2">n2 value</item></items>\[/code\]I can use the clojure.data.xml library's element function directly like this:\[code\](element :items {} (element :item {:name "n0"} "n0 value") (element :item {:name "n1"} "n1 value") (element :item {:name "n2"} "n2 value"))\[/code\]and this responds to emit-str as expected and prints the xml I am after.The problem I am having is that I have a variable number of items for a given items collection, so I want to do something that looks like this:\[code\](def collection-of-items [(element :item {:name "n0"} "n0 value") (element :item {:name "n1"} "n1 value")])(element :items {} collection-of-items)\[/code\]I.e., I make a collection of several xml element objects, and give that as the :content argument for the ':items' element definition. These two forms evaluate correctly, but then emit-str fails when invoked on the result of the element invocation. So my question is: How do I pass the 'collection-of-items' var to the element function as an argument so it will appear as a simple variable argument list? Or am I Missing the Clojure Boat completely here? Thanks all!
 
Top