(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 [{:tag :display-name "FooBar+"}
{:tag :listener
:attrs {:listener-class "com.example.server.Main"}}
{:tag :filter
:attrs {:filter-name "guiceFilter"
:filter-class "com.google.inject.servlet.GuiceFilter"}}
{:tag :filter-mappings
:attrs {:filter-name "guiceFilter"
{:url-pattern "/*"}}}]}))
In our last episode, Justin Kramer was kind enough to explain to me how clojure.xml/emit expects input to be formatted so it can produce usable xml. I’m still getting the same exception, but after I’ve looked the function over. I wonder if the xmlns:xsi, xmlns:web, and xsi:schemaLocation attributes under the web-app tag might be causing the exception because of the extra colon, but I don’t know enough to say for sure. Could someone please show me where I’m going wrong? Thank you for your time and consideration, and have a great day.
Your error has to do with your syntax – you have several maps in your code that have an odd number of forms, maps must have an even number (each key must have a value). For example, one of your maps:
Has 3 entries, which causes the error you’re seeing. Also note: What happened to closure.xml/emit?
HTH,
Kyle