I generated multiple classes from multiple XML files using JAXB xjc tool.
These XML files have common tag names, which involves that, when I generated the java classes I had multiple classes with the same name. I've put them into different packages and renamed them consequently.
But I still have this error:
The element name {}Document has more than one mapping. this problem is related to the following location: at public javax.xml.bind.JAXBElement com.xxx.generatedByJaxb.bal.ObjectFactory.createDocument(com.xxx.generatedByJaxb.bal.DocumentTypeBal) at com.xxx.generatedByJaxb.bal.ObjectFactory this problem is related to the following location: at public javax.xml.bind.JAXBElement com.xxx.generatedByJaxb.addr.ObjectFactory.createDocument(com.xxx.generatedByJaxb.addr.DocumentTypeAddr) at com.xxx.generatedByJaxb.addr.ObjectFactory
...Repeated many times in the console.
EDIT
When I first faced the conflict problem I renamed the conflicting classes, so for example:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "DocumentType", propOrder = { "addressPage" })
public class DocumentType {
Had been changed for:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "DocumentTypeAddr", propOrder = { "addressPage" })
public class DocumentTypeAddr {
I regenarated the classes, they are know without any manual change. Here is the error that I have:
Two classes have the same XML type name "DocumentType". Use @XmlType.name and @XmlType.namespace to assign different names to them. this problem is related to the following location: at com.xxx.generatedByJaxb.addr.DocumentType at public com.xxx.generatedByJaxb.addr.DocumentType com.xxx.generatedByJaxb.addr.ObjectFactory.createDocumentType() at com.xxx.generatedByJaxb.addr.ObjectFactory this problem is related to the following location: at com.xxx.generatedByJaxb.bal.DocumentType at public com.xxx.generatedByJaxb.bal.DocumentType com.xxx.generatedByJaxb.bal.ObjectFactory.createDocumentType() at com.xxx.generatedByJaxb.bal.ObjectFactory The element name {}Document has more than one mapping. this problem is related to the following location: at public javax.xml.bind.JAXBElement com.xxx.generatedByJaxb.bal.ObjectFactory.createDocument(com.xxx.generatedByJaxb.bal.DocumentType) at com.xxx.generatedByJaxb.bal.ObjectFactory this problem is related to the following location: at public javax.xml.bind.JAXBElement com.xxx.generatedByJaxb.addr.ObjectFactory.createDocument(com.xxx.generatedByJaxb.addr.DocumentType) at com.xxx.generatedByJaxb.addr.ObjectFactory
Here is an example of a xsd file (between the 7 xsd files that I generate the classes from):
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified">
<xs:element name="Document" type="DocumentType"/>
<xs:complexType name="DateType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="Type"/>
<xs:attribute type="xs:int" name="Date"/>
<xs:attribute type="xs:byte" name="HH"/>
<xs:attribute type="xs:byte" name="MM"/>
<xs:attribute type="xs:byte" name="SS"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="ChargeType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:short" name="Id" use="optional"/>
<xs:attribute type="xs:float" name="Amount" use="optional"/>
<xs:attribute type="xs:string" name="CurrCode" use="optional"/>
<xs:attribute type="xs:byte" name="Type" use="optional"/>
<xs:attribute type="xs:string" name="PT" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="BalancePageType">
<xs:sequence>
<xs:element type="DateType" name="Date"/>
<xs:element type="ChargeType" name="Charge" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="DocumentType">
<xs:sequence>
<xs:element type="BalancePageType" name="BalancePage"/>
</xs:sequence>
<xs:attribute type="xs:string" name="Sender"/>
<xs:attribute type="xs:string" name="Id"/>
<xs:attribute type="xs:string" name="BAId"/>
</xs:complexType>
</xs:schema>