【发布时间】:2011-03-14 19:59:42
【问题描述】:
在我的架构中,我有一些类型只是简单地扩展了一个简单的 XSD 类型(int 或 string)。 JAXB 为每个此类类型创建一个单独的 java 类。我想删除这个中间类并配置 JAXB 以尽可能使用原语(例如,用 java.lang.String 和 DocumentType 替换 CountryType 和 int 或 lava.lang.Integer)。例如,对于给定的 XSD,最好有 DestinationType.setDocumentType(int) 和 List<String> StatesType.getCountry()。我很高兴为此编写类型范围的an adapter,但看起来只支持来自原始 XML 类型的转换。也许可以进行每个属性类型的转换?请给出 JAXB 绑定自定义的任何示例,这可能会有所帮助。
<?xml version="1.0" encoding="UTF-8"?>
<schema
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:exch="http://www.mycompany.org/exchange"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
targetNamespace="http://www.mycompany.org/exchange"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<complexType name="countryType">
<simpleContent>
<extension base="string"/>
</simpleContent>
</complexType>
<complexType name="statesType">
<sequence maxOccurs="unbounded">
<element name="country" type="exch:countryType"/>
</sequence>
</complexType>
<complexType name="documentType">
<simpleContent>
<extension base="integer"/>
</simpleContent>
</complexType>
<complexType name="destinationType">
<sequence>
<element name="states" type="exch:statesType" maxOccurs="1"/>
<element name="document-type" type="exch:documentType" minOccurs="1" maxOccurs="1"/>
</sequence>
</complexType>
</schema>
【问题讨论】: