0

我正在使用 Castor XML 代码生成器。如果您有两个带有 complexTypes 定义如下的模式:

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

<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>

现在,Castor 从第二个模式生成 Foo 类型的字段 _foo,它是 FooBar 类的子类。

为什么一个名字不能只是一个名字?我知道这是为了避免命名冲突,但我希望在生成的类中使用 FooBar 类型的字段 _foo 。有任何想法吗?

4

1 回答 1

0

看起来答案取决于所使用的 Castor 版本。在较新的版本中,您似乎可以添加

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

到 binding.xml 文件,它将使用 FooBar 作为类。不过,这似乎在 1.05 版中不起作用,这是我正在使用的。由于我没有在较新的版本中测试上述内容,我不能保证它会工作/正确。

于 2009-08-17T14:27:33.047 回答