7

Given this XSD:

<xsd:element name="ServiceList">
    <xsd:complexType>
        <xsd:sequence>
            ...
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>

<xsd:complexType name="ServiceList">
    <xsd:sequence>
        ...
    </xsd:sequence>
</xsd:complexType>

What is kind of the semantic difference between these two? I.e. named elements and complexTypes which are direct children of a schema.

The reason for me asking is that I tried doing this in an XSD:

<xsd:element name="AvailableServices" type="cm:ServiceList" />
<xsd:element name="ExistingServices" type="cm:ServiceList" />
<xsd:complexType name="ServiceList">
    <xsd:sequence>
        ...
    </xsd:sequence>
</xsd:complexType>

But when this was compiled into Java classes using the Maven JAXB plugin, I am only able to create a new ServiceList(). AvailableServices and ExistingServices doesn't seem to even exist among the generated classes. So, what's going on here?

Svish
  • 152,914
  • 173
  • 462
  • 620
  • The following should help: http://blog.bdoughan.com/2012/07/jaxb-and-root-elements.html – bdoughan Nov 01 '12 at 14:26
  • So, basically, named complex types and named elements with anonymous complex type gets a class, while elements referring to a complexType do not? – Svish Nov 01 '12 at 14:35
  • Essentially, I've added an answer with a little more detail. – bdoughan Nov 01 '12 at 14:48

1 Answers1

2

Classes Correspond to Complex Types

In JAXB (JSR-222) Java classes correspond to complex types. Named complex types and anonymous complex types of global elements correspond to root level classes. Nested complex types by default are generated as static inner classes. You can change this default behaviour:

Global Elements

If a global element is uniquely associated with a complex type (global element with anonymous complex type) it will be annotated with @XmlRootElement. Global elements that correspond to global types will correspond to @XmlElementDecl annotations in the ObjectFactory class.

For More Information

Community
  • 1
  • 1
bdoughan
  • 147,609
  • 23
  • 300
  • 400