Mattos
Mattos

Reputation: 809

root element is already defined jaxb

My problem is that I have two Schemas A.xsd B.xsd

they both share the same root, I'm gonna try to exemplify

 A.xsd
 <xs:element name="A">
   <xs:complexType>
      .my elements on A
   </xs:complexType>
 </xs:element>

 B.xsd
 <xs:element name="A">
  <xs:complexType>
   .my elements on B
  </xs:complexType>
 </xs:element>

When I try to generate the classes the output is that element 'A' is Already defined. So I created a Binding file that defines to xsd A, creates for the element A a class C, and for xsd B creates for the element A a class D

 X.xjb
 <bindings schemaLocation="A.xsd">
  <bindings node="//xs:element[@name='A']">
   <class name="C">
  </bindings>
 </bindings>

 <bindings schemaLocation="B.xsd">
  <bindings node="//xs:element[@name='A']">
   <class name="D">
  </bindings>
 </bindings>

But didnt work, it outputs the same error, 'A' is Already defined, so I tried with property instead of class on the binding file.

 X.xjb
 <bindings schemaLocation="A.xsd">
  <bindings node="//xs:element[@name='A']">
   <property name="C">
  </bindings>
 </bindings>

 <bindings schemaLocation="B.xsd">
  <bindings node="//xs:element[@name='A']">
   <property name="D">
  </bindings>
 </bindings>

, didnt work either

They do not have a targetNamespace

Anyone ever did something like this?

Upvotes: 2

Views: 780

Answers (1)

Petru Gardea
Petru Gardea

Reputation: 21658

Just assign them to different Java packages and you should be fine.

<jxb:schemaBindings>
    <jxb:package name="primer.myPo">
        <jxb:javadoc>
            <![CDATA[<body> Package level documentation for generated package primer.myPo.</body>]]>
        </jxb:javadoc>
    </jxb:package>
    <jxb:nameXmlTransform>
        <jxb:elementName suffix="Element"/>
    </jxb:nameXmlTransform>
</jxb:schemaBindings>

Upvotes: 2

Related Questions