螺纹“主”螺纹中的异常java.lang.ArrayIndexOutOfBoundsException:3(test-xml.clj:6) [英] Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3 (test-xml.clj:6)
问题描述
我试图在clojure中编写一个函数,使用clojure.xml / emit打印出xml。
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 "/*"}}]}))
我知道异常是什么意思,但我不知道howit是否与我的代码有关。有人可以指出正确的方向吗?
完整的堆栈跟踪可以在 https:/ /gist.github.com/1838248
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
感谢您的时间和考虑
推荐答案
在Clojure 1.3中的错误是更有帮助:地图字面值必须包含偶数个形式。
The error for this in Clojure 1.3 is a bit more helpful: "Map literal must contain an even number of forms".
问题出现在:content
向量的最后两个条目中:它们是包含三种形式的文字映射。地图由键值对组成,因此必须包含偶数。
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.
此外,:content
看起来不像传递给 emit
的有效数据。每个节点应该有:tag
,:attrs
和:content
属性,或者是一个字符串。
Further, the stuff in :content
doesn't look like valid data to pass to emit
. Each node should have :tag
, :attrs
, and :content
attributes, or be a string.
这篇关于螺纹“主”螺纹中的异常java.lang.ArrayIndexOutOfBoundsException:3(test-xml.clj:6)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!