Java – hyperjaxb: exclude XML elements by XML attribute

I have a predefined XSD 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, Java util. Date replaces xmlregionancalendar, and I use 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

For now, I just need to do this for the date1 property instead of datelist1 Is there any way to use its attribute maxoccurs = "5" to exclude datelist1?

Solution

You can apply javatype customization locally to the generated properties It's like:

<bindings node=".../xs:element[@name='Date1']">
    <property>
        <baseType>
            <javaType .../>
        </baseType>
    </property>
</bindings>
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>