簡體   English   中英

使用jaxb從xml生成java類時缺少類

[英]missing class while generating java class from xml with jaxb

所以這是我的第一個問題。 :)

我嘗試從xsd文件生成java類。

所以我的問題如下。 不知何故,jaxb不會為簡單類型“Test”生成java類。

我在復雜類型中有兩個屬性,我對“Art”和“Nummer”感興趣

            <xs:attribute name="Art" use="required">
              <xs:annotation>
                <xs:documentation>Darf ausschließlich die Werte "BEL" (BEL-Leistung), "NBL"(andere, nicht in der BEL enthaltene Leistung), "EDM" (Edelmetalle oder -legierungen), "MAT" (alle anderen Materialien) oder "RBT" (Rabatt) enthalten. Jede Art kann mehrmals auftreten.</xs:documentation>
              </xs:annotation>
              <xs:simpleType>
                <xs:restriction base="Positionsart"/>
              </xs:simpleType>
            </xs:attribute>
            <xs:attribute name="Nummer" use="optional">
              <xs:annotation>
                <xs:documentation>Ausschließlich anzugeben, wenn Art="BEL". Es sind ausschließlich die offiziellen BEL-Nummern zu verwenden. BEL-Nummern müssen vierstellig übermittelt werden. Das Feld wird nicht übermittelt, wenn Art ungleich BEL ist.</xs:documentation>
              </xs:annotation>
              <xs:simpleType>
                <xs:restriction base="Test"/>
              </xs:simpleType>
            </xs:attribute>

這些類型都在xsd的末尾定義:

  <xs:simpleType name="Positionsart">
  <xs:simpleType name="Test">

這兩種類型中有更多,但stackoverflow告訴我,這將是很多代碼。 :)

但你可以看一下這里的文件:

https://www.dropbox.com/sh/u0j58gd1jo98qrn/L2Yw_-psOw

這就是課程開頭的樣子

   @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "")
    public static class Position {

        @XmlAttribute(name = "Art", required = true)
        protected Positionsart art;
        @XmlAttribute(name = "Nummer", required = true)
        protected String nummer;

如您所見,Art是一個Positionsart類型,就像在xsd中指定的那樣,但Number不是Test類型,它只是一個String。

我不明白這是什么問題。 兩個屬性之間的唯一區別是一個是必需的,另一個是optinal,但我試圖改變它。

另外我認為命名可能有問題。 SimpleType“Test”在命名為BEL2之前,所以我嘗試更改名稱。

此外,我發現在開頭有一個到命名空間的死鏈接,首先在這個文檔中沒有使用命名空間,其次我嘗試生成沒有這個命名空間的類。

為了生成類,我打開了命令行工具,導航到正確的位置並鍵入xjc Laborabrechnungsdaten.xsd。 我的Java變量已經到位。

我希望有人有個建議。

提前致謝。 :)

什么是相同的?

PositionsartTest都是XML Schema中的簡單類型(參見: https//www.dropbox.com/sh/u0j58gd1jo98qrn/F37X8kxa67/Laborabrechnungsdaten.xsd ),它們擴展了xs:string並定義了有效值的xs:enumeration

有什么不同?

Positionsart而不是Test生成Java枚舉的原因是Test類型包含的值不是有效的Java枚舉值。

  <xs:enumeration value="0010"/>
  <xs:enumeration value="0018"/>

對於這些無效值中的每一個,您將需要使用外部綁定文件來指定有效的枚舉值。 舉個例子,看看我在Stack Overflow上提出類似問題的答案

暫無
暫無

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

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