XMLBeans Support for Built-In Schema Types
XMLBeans Support for Built-In Schema Types
Just as with types in XML schema, the XMLBeans types based on schema are arranged in a hierarchy. In general, the hierarchy of XMLBean types mirrors the hierarchy of the schema types themselves. XML schema types all inherit from xs:anyType (which is at the root of the hierarchy); XMLBeans types inherit from XmlObject.
In XML schema, xs:anyType is the root type for two type categories: built-in and user-derived. Built-in schema types are common types defined by the XML schema specification. User-derived types are those you define in your schema. This topic lists the built-in types provided with XMLBeans. For information about user-derived types and the Java types generated from them, see Java Types Generated from User-Derived Schema Types.
The following figure illustrates the hierarchy of types, showing both built-in schema types and their XMLBeans parallels. Notice, too, that nearly all of the built-in types are also available as natural Java types.
Java Types Representing Built-In Schema Types
As you can see from the figure above, all 46 built-in schema types are represented by an XMLBean type provided with XMLBeans. When using built-in XMLBean types, keep in mind that:
- Since XmlObject corresponds to the xs:anyType, all Java XMLBean types inherit from XmlObject. Therefore all XMLBean types share the XmlObject interface�s ability to create an XmlCursor at the position of the object. They can also render the XML as strings or streams.
- Where there is a corresponding natural Java type, the XMLBeans type provides a way to get the underlying XML's value as the natural type. See the table in this topic for information on how natural Java types map to XMLBeans types.
- Values assigned to built-in XMLBeans types are validated in keeping with the rules of the schema type they represent. So, for example, an attempt to assign a negative integer value to an XmlPositiveInteger will throw an XmlValueOutOfRange exception.
The following table lists the built-in schema types, along with their XMLBeans and natural Java parallels. Unless otherwise noted, natural Java types are in the java.lang package; XMLBean types are in the org.apache.xmlbeans package.