在我的模式中,我有一些類型只是簡單地擴展了一個簡單的XSD類型(int或string)。 JAXB根據這種類型創建一個單獨的java類。我想放棄這個中間類並配置JAXB在可能的地方使用原語(例如用CountryType
與java.lang.String
和DocumentType
和int
或lava.lang.Integer
)。例如,對於給定的XSD,最好有DestinationType.setDocumentType(int)
和List<String> StatesType.getCountry()
。我很樂意爲此編寫類型爲an adapter,但看起來只支持來自原始XML類型的轉換。也許有可能使每個屬性類型轉換?請給出任何JAXB綁定定製的例子,這可以提供幫助。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>
可這種轉變沒有打破序列化的XML的兼容性應用? – 2010-07-13 12:51:46
@dma_k - 是的,這兩種類型的XML表示形式都是相同的。 – 2010-07-14 15:17:52