簡體   English   中英

如何解決Castor的默認行為,為complexType元素創建包裝器類?

[英]How can I work around Castor's default behaviour to create wrapper classes for complexType elements?

我正在使用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。 有任何想法嗎?

答案似乎取決於所使用的Castor的版本。 在較新的版本中,您似乎可以添加

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

到binding.xml文件,它將使用FooBar作為類。 但是,這似乎在1.05版中不起作用,這就是我正在使用的版本。 由於我尚未在較新的版本中測試上述內容,因此無法保證它會/正確。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM