线程“main”中的异常java.lang.ArrayIndexOutOfBoundsException:3(test-xml.clj:6)

发布于 2025-01-05 22:55:08 字数 1276 浏览 4 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自演自醉 2025-01-12 22:55:08

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 to emit. Each node should have :tag, :attrs, and :content attributes, or be a string.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文