Why does JAXB differentiate elements and types?



So, if you want to define a Java class from a Schema, you have to create a complex type for that Java class, and afterward you have to declare an XML element for that type.



<xs:complexType name="PersonType">
<xs:sequence>
<xs:element name="age" type="xs:int"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="occupation" type="xs:string"/>
</xs:sequence>
</xs:complexType>

<xs:element name="Person" type="myxml.PersonType"/>




My question is, why does JAXB differentiate between complexType and element? It seems to only create boilerplate code, where you have to nominally declare a class type twice.


For example, this would seem simpler (of course, it won't compile):



<xs:element name="Person">
<xs:sequence>
<xs:element name="age" type="xs:int"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="occupation" type="xs:string"/>
</xs:sequence>
</xs:element>


Could someone please point out the design rationale behind this aspect of JAXB?


No comments:

Post a Comment