1

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>
Sinda MOKADDEM
  • 796
  • 2
  • 12
  • 35

1 Answers1

2

This is not a full answer (which is not possible under the given conditions), but it aims to provide first pointers.

It is hard to help you if you can't show any of your code. If your original stuff is confidential, try to make an anonymized samples.

So here's some very general advice:

I guess that the best way to proceed for you would be to put together a small non-confidential example, which is still demonstrative and relevant to your use case.

lexicore
  • 42,748
  • 17
  • 132
  • 221
  • I already manually renamed some classes: see my edit. Can it cause the problem? Shall all undo all the rename actions ? – Sinda MOKADDEM Oct 14 '14 at 16:39
  • Sorry, I can't provide advice without knowing the whole picture. Generally renaming or modifying generated code in any way is not a good idea since your changes will void on the next generation. But this is NOT an advice to revert anything. – lexicore Oct 14 '14 at 16:54