I’m trying to write a function in clojure that prints out xml using clojure.xml/emit.
(ns test.xml.emit
(:use clojure.core)
(:require [clojure.xml :as xml]))
(defn testemit []
(xml/emit {:tag :web-app
:attrs {:xmlns:xsi "http://www.w3.org/2001/XMLSchema-instance"
:xmlns "http://java.sun.com/xml/ns/javaee"
:xmlns:web "http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
:xsi:schemaLocation "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
:id "Foo"
:version "1.0"},
:content [{:display-name "FooBar+"}
{:listener
{:listener-class "com.example.server.Main"}}
{:filter
{:filter-name "guiceFilter"}
{:filter-class "com.google.inject.servlet.GuiceFilter"}}
{:filter-mappings
{:filter-name "guiceFilter"}
{:url-pattern "/*"}}]}))
I know what the exception means, but I’m not sure howit relates to my code. Could someone please point me in the right direction?
The full stack trace is available at https://gist.github.com/1838248
Thank you for your time and consideration
The error for this in Clojure 1.3 is a bit more helpful: “Map literal must contain an even number of forms”.
The problem is in the last two entries of the
:contentvector: they are literal maps containing three forms. Maps consist of key-value pairs, so must contain an even number.Further, the stuff in
:contentdoesn’t look like valid data to pass toemit. Each node should have:tag,:attrs, and:contentattributes, or be a string.