pokeRex110
pokeRex110

Reputation: 855

JAX-B class generation from schema compound by multiple files

I am using JAX-b to generate classes out of an XSD schema (compound by multiple files, and I dont know whether this is the problem) and the result is not what I was expecting.The objects created does not provide getters for single attributes but they offer getter for the list of the attributes as Object, and I have to cast each object manually.

i.e. the file lom.xsd has:

  <xs:include schemaLocation="common/elementTypes.xsd"/>
  <xs:include schemaLocation="common/rootElement.xsd"/>

in the file elementTypes.xsd we have:

    <xs:complexType name="lom">
      <xs:choice minOccurs="0" maxOccurs="unbounded">
         <xs:group ref="general"/>
         <xs:group ref="lifeCycle"/>
       </xs:choice>
      </xs:complexType>

instead in the rootElement.xsd we have

     <xs:element name="lom" type="lom">
       <xs:unique name="lomUnique">
         <xs:selector xpath="*"/>
         <xs:field xpath="@uniqueElementName"/>
      </xs:unique>
     </xs:element>

What I get is the class:

 public class General{
      List<Object> titleOrlifeCicle
 }

and I would pretend to have:

   public class General{
     String title;
     String lifeCicle
   }

In other schema it works fine, but it looks like with schema in different files it doesnt help that much. Is there any way to get the second version from the schema? Thank you.

Upvotes: 2

Views: 254

Answers (1)

Petru Gardea
Petru Gardea

Reputation: 21638

One thing to be sure about is that correctly having the same content in numerous XSDs vs. few, wouldn't change the outcome of your generation process. The problem in your case is that your schema makes heavy use of xsd:choice, hence the naming of your getters. The choice being unbounded, you're getting a list; you could make the names friendlier, using custom bindings, but that won't change the underlying structure. In your case, you would have to navigate The objects in the list, try to see if they match a class "General" or "LifeCycle", which will have the strings you're looking for the attributes you're after (see diagram below).

LOM.xsd

Upvotes: 1

Related Questions