【发布时间】:2016-06-28 10:42:17
【问题描述】:
我正在尝试从 XSD 生成 Java 源代码,并且必须使用 JAXWS 禁用包装器样式。我已经编写了自定义绑定,但似乎 JAXWS 不适用于 XJC。我使用的绑定非常简单。
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" xmlns="http://java.sun.com/xml/ns/jaxws"
version="2.1" jaxb:extensionBindingPrefixes="xjc">
<jaxb:bindings>
<jaxb:globalBindings typesafeEnumMaxMembers="2000" generateElementProperty="false" >
<jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
</jaxb:globalBindings>
</jaxb:bindings>
如果我尝试运行 ant 脚本,则会收到以下错误消息。
[xjc] [ERROR] Unsupported binding namespace "http://java.sun.com/xml/ns/jaxws". Perhaps you meant "http://java.sun.com/xml/ns/jaxb/xjc"?
[xjc] line 2 of file:/D:/xxxxxxxxxx/xxxxx/xxxx.xsd
[xjc] [ERROR] cvc-complex-type.2.4.a: Invalid content was found starting with element 'jaxws:enableWrapperStyle'. One of '{"http://java.sun.com/xml/ns/jaxb":javaType, "http://java.sun.com/xml/ns/jaxb":serializable, "http://java.sun.com/xml/ns/jaxb/xjc":serializable, "http://java.sun.com/xml/ns/jaxb/xjc":superClass, "http://java.sun.com/xml/ns/jaxb/xjc":superInterface, "http://java.sun.com/xml/ns/jaxb/xjc":typeSubstitution, "http://java.sun.com/xml/ns/jaxb/xjc":smartWildcardDefaultBinding, "http://java.sun.com/xml/ns/jaxb/xjc":simple, "http://java.sun.com/xml/ns/jaxb/xjc":treatRestrictionLikeNewType, "http://java.sun.com/xml/ns/jaxb/xjc":javaType, "http://java.sun.com/xml/ns/jaxb/xjc":generateElementProperty, "http://java.sun.com/xml/ns/jaxb/xjc":noMarshaller, "http://java.sun.com/xml/ns/jaxb/xjc":noUnmarshaller, "http://java.sun.com/xml/ns/jaxb/xjc":noValidator, "http://java.sun.com/xml/ns/jaxb/xjc":noValidatingUnmarshaller}' is expected.
[xjc] line 8 of file:/D:/xxxxxxxxxx/xxxxx/xxxx/xsd/xsd-binding.xml
我已经尝试过只使用 jaxws,但是 XJC 期望 JAXB 作为主要绑定。 使用此绑定:
<bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://java.sun.com/xml/ns/jaxws"
jaxb:version="2.1" extensionBindingPrefixes="xjc annox">
<enableWrapperStyle>false</enableWrapperStyle>
<jaxb:bindings>
<jaxb:globalBindings typesafeEnumMaxMembers="2000" generateElementProperty="false" />
</jaxb:bindings>
</bindings>
我收到了错误:
[xjc] [ERROR] not an external binding file. The root element must be {http://java.sun.com/xml/ns/jaxb}bindings but it is {http://java.sun.com/xml/ns/jaxws}bindings
[xjc] line ? of file:/D:/xxxxxx/xsd-binding.xml
[xjc] [ERROR] Unexpected <bindings> appears at line 4 column 61
[xjc] line 4 of file:/D:/xxxxxx/xsd-binding.xml
可以在 jaxb 中使用jaxws:enableWrapperStyle 吗?如果是,我忽略了什么?提前谢谢!
【问题讨论】: