The Apache Software Foundation > Apache XMLBeans
 

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.

Built-In Schema Type XMLBean Type Natural Java Type
xs:anyType XmlObject org.apache.xmlbeans.XmlObject
xs:anySimpleType XmlAnySimpleType String
xs:anyURI XmlAnyURI String
xs:base64Binary XmlBase64Binary byte[]
xs:boolean XmlBoolean boolean
xs:byte XmlByte byte
xs:date XmlDate java.util.Calendar
xs:dateTime XmlDateTime java.util.Calendar
xs:decimal XmlDecimal java.math.BigDecimal
xs:double XmlDouble double
xs:duration XmlDuration org.apache.xmlbeans.GDuration
xs:ENTITIES XmlENTITIES String
xs:ENTITY XmlENTITY String
xs:float XmlFloat float
xs:gDay

XmlGDay

java.util.Calendar
xs:gMonth XmlGMonth java.util.Calendar
xs:gMonthDay XmlGMonthDay java.util.Calendar
xs:gYear XmlGYear java.util.Calendar
xs:gYearMonth XmlGYearMonth java.util.Calendar
xs:hexBinary XmlHexBinary byte[]
xs:ID XmlID String
xs:IDREF XmlIDREF String
xs:IDREFS XmlIDREFS String
xs:int XmlInt int
xs:integer XmlInteger java.math.BigInteger
xs:language XmlLanguage String
xs:long XmlLong long
xs:Name XmlName String
xs:NCName XmlNCNAME String
xs:negativeInteger XmlNegativeInteger java.math.BigInteger
xs:NMTOKEN XmlNMTOKEN String
xs:NMTOKENS XmlNMTOKENS String
xs:nonNegativeInteger XmlNonNegativeInteger java.math.BigInteger
xs:nonPositiveInteger XmlNonPositiveInteger java.math.BigInteger
xs:normalizedString XmlNormalizedString String
xs:NOTATION XmlNOTATION Not supported
xs:positiveInteger XmlPositiveInteger java.math.BigInteger
xs:QName XmlQName javax.xml.namespace.QName
xs:short XmlShort short
xs:string XmlString String
xs:time XmlTime java.util.Calendar
xs:token XmlToken String
xs:unsignedByte XmlUnsignedByte short
xs:unsignedInt XmlUnsignedInt long
xs:unsignedLong XmlUnsignedLong java.math.BigInteger
xs:unsignedShort XmlUnsignedShort int

Related Topics