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 element
s and complexType
s 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?
A complex type is essentially a type definition for elements that may contain attributes and elements. An element can be declared with a type attribute that refers to a complexType element that defines the structure, content, and attributes of that element.
XSD elements can be of type simpleType , complexType , or anyType . An element of type simpleType contains only text. It cannot have attributes and elements. An element of type complexType can contain text, elements, and attributes.
An element definition within the XSD must have a name property, this is the name that will appear in the XML document. The type property provides the description of what can be contained within the element when it appears in the XML document.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With