2

Here are two xsd definitions, both of them are almost 90% similar.Below are the skeleton of the first xsd:

XSD1 :

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="apf2doc">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="request"/>
                <xs:element ref="account"/>
                <xs:element ref="financial_transaction"/>
                <xs:element ref="event_data" minOccurs="0"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

And second xsd is:

XSD2:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="apf2doc">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="request"/>
                <xs:element ref="account"/>
                <xs:element ref="message"/>
                <xs:element ref="event_data" minOccurs="0"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

Now these two xsds generate two sets of classes in two different packages. I am using JAXB to unmarshall the xmls received. The xmls are generated from these two xsds.

While creating a JAXB context it throws me error because most of the classes cause conflict I believe.

Here is the error trace:

The element name {}userid has more than one mapping. This problem is related to the     following location: 
at public javax.xml.bind.JAXBElement   
generated.order.ObjectFactory.createUserid(java.lang.String) at   
generated.order.ObjectFactory this problem is related to the following location:
at public javax.xml.bind.JAXBElement   
generated.usage.ObjectFactory.createUserid(java.lang.String) at 
generated.usage.ObjectFactory 

It would be great if someone can suggest me any solution.

Thanks.

dharam
  • 7,882
  • 15
  • 65
  • 93
  • I know this is old, but [the solution I posted in another question](https://stackoverflow.com/a/71072922/2516673) might be of help for someone. – Fappaz Feb 10 '22 at 22:12

1 Answers1

2

Since your 2 XML schemas have global elements with the same name and namespace you won't be able to create a single JAXBContext on both models. You can do one of the following:

  1. Create a separate JAXBContext for each model.
  2. Use namespaces to differentiate the 2 XML schemas.
bdoughan
  • 147,609
  • 23
  • 300
  • 400
  • Hi, Thank for the answer. I believe I have to go the first war, creating separate JAXBContext because I cannot change the namespaces, its a third party thing here. :( – dharam Dec 19 '12 at 11:11