【问题标题】:How can I work around Castor's default behaviour to create wrapper classes for complexType elements?如何解决 Castor 的默认行为来为 complexType 元素创建包装类?
【发布时间】:2009-08-14 03:07:10
【问题描述】:

我正在使用 Castor XML 代码生成器。如果您有两个 schema 的 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 。有什么想法吗?

【问题讨论】:

    标签: java xsd castor


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-24
      相关资源
      最近更新 更多