Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7533645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:47:06+00:00 2026-05-30T05:47:06+00:00

I am a Clojure n00b trying to create some XML strings. My goal is

  • 0

I am a Clojure n00b trying to create some XML strings.

My goal is to create something like this:

<?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>

I can use the clojure.data.xml library’s element function directly like this:

(element :items {} 
  (element :item {:name "n0"} "n0 value")
  (element :item {:name "n1"} "n1 value")
  (element :item {:name "n2"} "n2 value"))

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:

(def collection-of-items 
    [(element :item {:name "n0"} "n0 value") 
     (element :item {:name "n1"} "n1 value")])

(element :items {} 
  collection-of-items)

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T05:47:07+00:00Added an answer on May 30, 2026 at 5:47 am

    Use apply:

    user=> (def collection-of-items 
        [(element :item {:name "n0"} "n0 value") 
         (element :item {:name "n1"} "n1 value")])
    #'user/collection-of-items
    user=> (def b (apply element :items {} collection-of-items))
    #'user/b
    user=> b
    #clojure.data.xml.Element{:tag :items, :attrs {}, :content (#clojure.data.xml.Element{:tag :item, :attrs {:name "n0"}, :content ("n0 value")} #clojure.data.xml.Element{:tag :item, :attrs {:name "n1"}, :content ("n1 value")})}
    user=> (emit-str b)
    "<?xml version=\"1.0\" encoding=\"UTF-8\"?><items><item name=\"n0\">n0 value</item><item name=\"n1\">n1 value</item></items>"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In clojure, it is possible to destructure some keys of a map like this:
In clojure, I can destructure a map like this: (let [{:keys [key1 key2]} {:key1
More Clojure weirdness. I have this function I'm trying to define and call. It
In clojure I have lines like this that define default values: (def *http-port* 8080)
Learning clojure, trying to create a lazy infinite sequence of all prime numbers. I'm
In clojure, I would like to create a record inside a function. I tried:
Hello Clojure experts, I am trying to do some timing tests in Clojure 1.3
Clojures clojure.xml/parse, clojure.zip/xml-zip and clojure.contrib.zip-filter.xml/xml-> are excellent tools for pulling values out of xml,
In clojure you can create a SwingWorker proxy and implement doInBackground and do methods.
Using clojure, I've been able to successfully setup log4j very simply by using this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.