线程“main”中的异常java.lang.ArrayIndexOutOfBoundsException:3(test-xml.clj:6)
我正在尝试在 clojure 中编写一个函数,使用 clojure.xml/emit 打印出 xml。
(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 "/*"}}]}))
我知道异常意味着什么,但我不确定它与我的代码有何关系。有人可以指出我正确的方向吗?
完整的堆栈跟踪可在 https://gist.github.com/1838248 获取,
感谢您的支持时间和考虑
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Clojure 1.3 中的错误更有帮助:“映射文字必须包含偶数个形式”。
问题出在
:content
向量的最后两个条目中:它们是包含三种形式的文字映射。映射由键值对组成,因此必须包含偶数。此外,
:content
中的内容看起来不像传递给emit
的有效数据。每个节点应该具有:tag
、:attrs
和:content
属性,或者是一个字符串。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
:content
vector: they are literal maps containing three forms. Maps consist of key-value pairs, so must contain an even number.Further, the stuff in
:content
doesn't look like valid data to pass toemit
. Each node should have:tag
,:attrs
, and:content
attributes, or be a string.