简体   繁体   中英

Hyperjaxb: Exclude XML Element by XML property

I have a predefined XSD that looks as follows:

<xs:element name="JavaClass1">
    <xs:complexType>
        <xs:sequence>
            ...
            <xs:element name="Date1" type="xs:date" minOccurs="0">
            </xs:element>
            <xs:element name="DateList1" type="xs:date" minOccurs="0" maxOccurs="5">
            </xs:element>
            ...
        </xs:sequence>
    </xs:complexType>
</xs:element>

In order to generate Java classes from XSD and at the same time replace XMLGregorianCalendar with java.util.Date , I used the following external binding:

<globalBindings>
    <javaType
        name="java.util.Date"
        xmlType="xs:dateTime"
        parseMethod="XsdDateTimeConverter.unmarshal"
        printMethod="XsdDateTimeConverter.marshalDateTime"
    />
    <javaType
        name="java.util.Date"
        xmlType="xs:date"
        parseMethod="XsdDateTimeConverter.unmarshal"
        printMethod="XsdDateTimeConverter.marshalDate"
    />
</globalBindings>

I found this solution here .

Now, I need to do this only for the attribute Date1 and not for DateList1 . Is there a way how to exclude DateList1 by using it's property maxOccurs="5" ?

You can apply the javaType customization locally to the generated property. Something like:

<bindings node=".../xs:element[@name='Date1']">
    <property>
        <baseType>
            <javaType .../>
        </baseType>
    </property>
</bindings>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM