users@jaxb.java.net

How to customize undefined schema-types?

From: Erik Ghint <erik.ghint_at_gmail.com>
Date: Wed, 23 Nov 2005 10:21:38 +0100

Hi there,

I try to compile/generate JAXB-Classes from a xml-schema with the XJC-compiler.
Some of the elements within this schema have no defined type.
Therefore XJC create a class-property of type "AnyType".
Although I am able to select this specific node in the binding-file I
am not able to change the java-type for those undefined elements.

Is there a solution or even a good work-around?

This examples may illustrate the problem:

exmpl.xsd:
[...]
<complexType name="person">
 <sequence>
   <element name="firstname" type="xsd:string" />
   <element name="lastname" />
 </sequence>
</complexType>
[...]

exmpl.xjb:
[...]
<jaxb:bindings node="//xs:complexType[@name='person']">
 <jaxb:bindings node=".//xs:element[@name='lastname']">
   <jaxb:property name="surname">
     <jaxb:baseType>
       <jaxb:javaType name="java.lang.String" parseMethod="..."
printMethod="..."/>
     </jaxb:baseType>
   </jaxb:property>
</jaxb:bindings>

The result:
Person.java
public interface Person extends ...{
 public void setFirstname(String firstname);
 public String getFirstname();
//and now this :-(
 public void setSurname(AnyType surname);
 public AnyType getSurname(); //The property is not a String but AnyType ...
}

Sincerly,
EG