2009-08-14 22 views
0

我正在使用Castor XML代碼生成器。如果你有兩個模式與定義複合類型如下:如何解決Castor的默認行爲以創建complexType元素的包裝類?

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

現在,從第二個架構蓖麻產生Foo類型的字段_foo那就是FooBar的類的子類。

爲什麼不能只是一個名字?我知道這是爲了避免命名衝突,但我希望在我生成的類中有一個FooBar類型的字段_foo。有任何想法嗎?

回答

0

看起來答案取決於正在使用的Castor版本。在新版本中,似乎可以添加

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

到binding.xml文件,它會用FooBar的作爲類。這似乎並不適用於1.05版本,​​這正是我正在使用的版本。由於我沒有在較新版本中測試過以上版本,我不能保證它能正常工作。

相關問題