Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

missing class while generating java class from xml with jaxb

Tags:

java

xml

jaxb

xsd

so this is my first question. :)

I try to generate java classes from a xsd file.

So my Problem is the following. Somehow jaxb won't generate a java class for the simple type "Test".

I have two attributes within a complex type that i am interested in "Art" and "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>

The types are both defined at the end of the xsd:

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

There is more in those two types but stackoverflow told me that it would be to much code. :)

But you can have a look at the files here:

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

This is how the beginning of the class looks like

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

As you can see, Art is a Positionsart type like it is specified in the xsd but Number is not a Test type it is just a String.

I don't understand what the issue is. The only difference between the two attributes is that the one is required and the other is optinal, but I tried to change that already.

Also I thought that there might be a problem with the naming. The SimpleType "Test" was before named BEL2 so I tried changing the name.

Furthermore I found that in the beginning there is a dead link to a namespace, first of all the namespace is not used in this document and second of all I tried to generate the classes without this namespace.

To generate the classes I opened the command line tool, navigated to the right location and typed xjc Laborabrechnungsdaten.xsd. My Java variables are in place.

I hope someone has a suggestion.

Thanks in advance. :)

like image 369
Eric Avatar asked Apr 19 '26 04:04

Eric


1 Answers

What's the Same?

Positionsart and Test are both simple types in your XML Schema (see: https://www.dropbox.com/sh/u0j58gd1jo98qrn/F37X8kxa67/Laborabrechnungsdaten.xsd) that extend xs:string and define an xs:enumeration of valid values.

What's Different?

The reason that a Java enum is generated for Positionsart and not Test is that the Test type contains values that are not valid Java enum values.

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

For each of these invalid values you will need to use an external binding file to specify a valid enum value. For an example see this answer I gave to a similar question on Stack Overflow

  • Xml Schema / JaxB -- How to enable empty enumerations, string, integer values in schema without validation errors?
like image 70
bdoughan Avatar answered Apr 20 '26 16:04

bdoughan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!