簡體   English   中英

遞歸xsd生成帶有對象而不是給定類型的Java類

[英]recursive xsd generates java class with Objects instead of the given Type

因此,我有一個對象,可以包含該類型的對象列表。 我寫了一個看起來像這樣的XSD:

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="myNamespace" elementFormDefault="qualified">  
   <complexType name="BinModel">
      <sequence>
         <element type="string" name="min" />
         <element type="string" name="max" />
         <element type="string" name="fieldname" /> 
         <element type="int" name="defaultValue" />
         <element xmlns:ref="BinModel" name="innerBins" maxOccurs="unbounded" minOccurs="0" />
      </sequence>  
   </complexType>
   <element name="AllBins">  
      <complexType>  
         <sequence>  
            <element type="string" name="fieldnames" maxOccurs="unbounded" minOccurs="0"/>
            <element type="int" name="defaultValue"/>
            <element xmlns:type="BinModel" name="outerBins" maxOccurs="unbounded" minOccurs="0" />
         </sequence>
      </complexType>  
   </element>
</schema>

它產生兩個Java類,分別是BinModel和AllBins,但是在每個這些類中,即使我指定它們都包含BinModel類型的列表,它BinModel產生Object類型的List。

如何生成具有BinModel列表的BinModel

所以我意識到當我在typeref之前添加xmlns以便不顯示編輯器中的錯誤時出現了問題。 我在愚蠢的巨大代碼庫中的另一個地方查看了另一個xsd,以找到一個遞歸定義的對象,以嘗試找到解決方案並發現了兩件事。 1.我們定義了自己的命名空間。2.在該命名空間中引用了我們自己的對象。

因此,更正后的代碼如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:myProject="projectNamespace" targetNamespace="myNamespace" elementFormDefault="qualified">  
  <complexType name="BinModel">
     <sequence>
        <element type="string" name="min" />
        <element type="string" name="max" />
        <element type="string" name="fieldname" /> 
        <element type="int" name="defaultValue" />
        <element type="myProject:BinModel" name="innerBins" maxOccurs="unbounded" minOccurs="0" />
     </sequence>  
  </complexType>
  <element name="AllBins">  
     <complexType>  
        <sequence>  
           <element type="string" name="fieldnames" maxOccurs="unbounded" minOccurs="0"/>
           <element type="int" name="defaultValue"/>
           <element type="myProject:BinModel" name="outerBins" maxOccurs="unbounded" minOccurs="0" />
        </sequence>
     </complexType>  
   </element>
</schema>

暫無
暫無

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

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