假设我具有以下XSD定义(摘自FpML 5.11):
setTimeout
假设我还想使用XJC简单绑定来生成JAXB代码:
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.fpml.org/FpML-5/confirmation"
targetNamespace="http://www.fpml.org/FpML-5/confirmation">
<xsd:complexType name="CreditEventNoticeDocument">
<xsd:sequence>
<xsd:element name="eventContent" type="xsd:string"/>
<xsd:element name="eventDate" type="xsd:date"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="creditEventNotice" type="CreditEventNoticeDocument"/>
<xsd:complexType name="CreditEventNotice">
<xsd:sequence>
<xsd:element name="notifyingParty" type="xsd:string"/>
<xsd:element name="noticeDate" type="xsd:date"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
通常,这将导致<?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:xsd="http://www.w3.org/2001/XMLSchema" version="2.1">
<jaxb:globalBindings generateElementProperty="false">
<jaxb:serializable/>
<xjc:simple/>
</jaxb:globalBindings>
</jaxb:bindings>
声明与<xsd:element name="creditEventNotice"
冲突,并且建议的解决方法是将绑定自定义添加到元素之一。我注意到,虽然我可以轻松地将自定义附加到<xsd:complexType name="CreditEventNotice">
元素上,但我还是更喜欢自定义xsd:complexType
(因为从逻辑上讲,这是名称错误的那个)-但是我无法找到将自定义项附加到它的方法,这样它实际上将导致无错误的XJC生成。这是我尝试执行的操作:
xsd:element
当我使用<jaxb:bindings ...>
<jaxb:globalBindings ... />
<jaxb:bindings schemaLocation="./test.xsd" node="/xsd:schema">
<jaxb:bindings node="xsd:element[@name='creditEventNotice']">
<jaxb:class name="CreditEventNoticeDocument"/>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
时,绑定被识别,但没有效果-我仍然遇到jaxb:class
错误。当我改用Two declarations cause a collision in the ObjectFactory class.
时,出现错误jaxb:property
。
所以我的问题是,如何正确自定义顶级compiler was unable to honor this property customization. It is attached to a wrong place, or its inconsistent with other bindings
?甚至有可能吗,或者即使在语义上没有意义,我是否也必须解决重命名其他元素的问题?