1
votes

I have two xsd being import to the main xsd. Both have the same elements but just different namespace. So, I created a customized binding for the second xsd(B.xsd). I am still getting 'Two declarations cause a collision in the ObjectFactory class'. As far I understand, customized binding would actually provide a meaningful customized names for cases that the default XML name-to-Java identifier mapping cannot handle automatically.Thus, collisions will be avoided.

A.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="urn:abc:def:ghi" xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:element name="lotNumber" type="xs:string"/>
    <xs:element name="itemExpirationDate" type="xs:date" />

</xs:schema>

B.xsd

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
     xmlns="http://abc.def.org/kj/ns"
     targetNamespace="http://abc.def.org/kj/ns"
     elementFormDefault="qualified"
     attributeFormDefault="unqualified">
    <xs:element name="ilmd">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="lotNumber" minOccurs="0"/>
                <xs:element ref="itemExpirationDate" minOccurs="0"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="lotNumber" type="xs:string"/>
    <xs:element name="itemExpirationDate" type="xs:string"/>
</xs:schema>

binding.xml

<jaxb:bindings
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.0">

    <jaxb:bindings
        schemaLocation="./xsd/B.xsd" node="/xs:schema">

        <jaxb:bindings node="//*/xs:element[@name='lotNumber']">
            <jaxb:property name="ucbLotNumber" />
        </jaxb:bindings>

        <jaxb:bindings node="//*/xs:element[@name='itemExpirationDate']">
            <jaxb:property name="ucbItemExpiratonDate" />
        </jaxb:bindings>

    </jaxb:bindings>

</jaxb:bindings>

pom.xml

<plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-xjc-plugin</artifactId>
                <configuration>
                    <extensions>
                        <extension>org.apache.cxf.xjcplugins:cxf-xjc-ts:3.0.3</extension>
                    </extensions>
                </configuration>
                <executions>
                    <execution>
                        <id>Xsd2Java</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>xsdtojava</goal>
                        </goals>
                        <configuration>
                            <sourceRoot>${basedir}/target/generated-sources/cxf</sourceRoot>
                            <xsdOptions>
                                <xsdOption>
                                    <xsd>${basedir}/src/main/resources/xsd/Main.xsd</xsd>
                                    <packagename>abc.def</packagename>
                                    <bindingFile>src/main/resources/binding.xml</bindingFile>
                                    <extension>true</extension>
                                    <extensionArgs>
                                        <arg>-encoding</arg>
                                        <arg>UTF-8</arg>
                                    </extensionArgs>
                                </xsdOption>
                            </xsdOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
1
Do you find a solution ?Bilgehan

1 Answers

0
votes

if element contains complextype inside,You should add name attribute to complextype

<xs:element name="ilmd">
        <xs:complexType **name="ilmdArray"**>
            <xs:sequence>
                <xs:element ref="lotNumber" minOccurs="0"/>
                <xs:element ref="itemExpirationDate" minOccurs="0"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>