tags:

views:

47

answers:

1

I'm using Castor XML code generator. If you have two schemas with complexTypes defined as follows:

<xs:schema ...blah...>
  <xs:complexType name="FooBarType">
    <xs:sequence>
      <xs:element name="meh"/>
      ...etc...
    </xs:sequence>
  </xs:complexType>
  <xs:element name="FooBar"/>
</xs:schema>

and

<xs:schema ...blah ...>
  <xs:include schemaLocation="FooBar.xsd">
  <xs:complexType name="AnotherSchemaType">
    <xs:sequence>
      <xs:element name="foo" type="FooBarType"/>
      ...etc...
    </xs:sequence>
  </xs:complexType>
  <xs:element name="AnotherSchema"/>
</xs:schema>

Now, from the second schema Castor generates the field _foo of type Foo that is a subclass of the FooBar class.

Why can't a name just be a name? I understand it's to avoid naming collisions, but I want a field _foo of type FooBar in my generated class. Any ideas?

A: 

It looks like the answer depends on the version of Castor being used. In newer versions it seems you can add

<elementBinding name="/complexType:AnotherSchemaType/foo">
  <java-class name="FooBar"/>
</elementBinding>

to the binding.xml file and it will use FooBar as the class. This doesn't appear to work in version 1.05 though, which is what I'm using. Since I haven't tested the above in newer versions I cannot guarantee that it will work/is correct.

ntownsend