4

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"?

Community
  • 1
  • 1
Erzen
  • 169
  • 10

1 Answers1

0

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>
lexicore
  • 42,748
  • 17
  • 132
  • 221
  • The thing is, like **Date1** trhere are many other elements that must be customized. So I am looking for something like ` ` So exluding some elements, but not by name rather by a xml property. In this case _maxOccurs_. – Erzen Jun 05 '16 at 13:04
  • Just modify the XPath and use `multiple="true"`. – lexicore Jun 05 '16 at 19:43