如何修复JAXB不支持的绑定命名空间错误?

时间:2014-02-05 14:04:41

标签: java xml jaxb

我正在使用JAXB从DTD生成绑定类。

我有一个自定义绑定文件binding.xjb,如下所示

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings 
  xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
  xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd "
>

  <jaxb:globalBindings generateValueClass="false">
    <xjc:simple />
  </jaxb:globalBindings>
</jaxb:bindings>

当我运行xjc编译器时,如下

xjc -dtd -d target/generated-sources/  -b src/main/jaxb/binding.xjb -p com.example src/main/jaxb/my-dtd.dtd

我收到以下错误

[ERROR] Unsupported binding namespace "http://java.sun.com/xml/ns/jaxb". Perhaps you meant "http://java.sun.com/xml/ns/jaxb/xjc"?
  line 7 of file:/Users/.../Development/projects/fuel/src/main/jaxb/binding.xjb

[ERROR] cvc-elt.1: Cannot find the declaration of element 'jaxb:bindings'.
  line 7 of file:/Users/.../Development/projects/fuel/src/main/jaxb/binding.xjb

[ERROR] Unsupported binding namespace "http://java.sun.com/xml/ns/jaxb". Perhaps you meant "http://java.sun.com/xml/ns/jaxb/xjc"?
  line 9 of file:/Users/.../Development/projects/fuel/src/main/jaxb/binding.xjb

Failed to parse a schema.

据我所知,我的绑定XML是有效的。我错过了什么吗?

我在MacOS上使用Java 1.7(Mavericks)

java -version返回

java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

xjc -version返回

xjc 2.2.4-2

0 个答案:

没有答案