Methods for Types Generated From Schema
Methods for Types Generated From Schema
As you may have seen in Getting Started with XMLBeans, you use the types generated from schema to access XML instances based on the schema. If you're familiar with the JavaBeans technology, the conventions used in the generated API will be recognizable.
In general, elements and attributes are treated as "properties" in the JavaBeans sense. In other words, as you would with JavaBeans properties, you manipulate parts of the XML through accessor methods such as getCustomer() (where you have a "customer" element), setId(String) (where you have an "id" attribute), and so on. However, because schema structures can be somewhat complex, XMLBeans provides several other method styles for handling those structures in XML instances.
Prototypes for Methods in Generated Interfaces
Several methods are generated for each element or attribute within the complex type. This topic lists each method that could be generated for a given element or attribute.
Note that whether or not a given method is generated is based on how the element or attribute is defined in schema. For example, a customer element definition with a maxOccurs attribute value of 1 will result in a getCustomer method, but not a getCustomerArray method — after all, only one customer element is possible in an instance document.
Note, too, that there may be two sets of parallel methods: one whose prototype starts with an "x". An "x" method such as xgetName or xsetName would be generated for elements or attribute whose type is a simple type. A simple type may be one of the 44 built-in simple types or may be a restriction in schema of one of those built-in types. Of course, an attribute will always be of a simple type. For built-in simple types, an "x" method will get or set one of the types provided with XMLBeans, such as XmlString , XmlInteger , XmlGDay , and so on. For derived types, the "x" method will get or set a generated type.
Single Occurrence Methods
Methods generated for elements or attributes that allow a single occurrence. An element is singular if it was declared with maxOccurs="1". An attribute is singular if it was not declared with use="prohibited".
Returns or sets the value of Foo. Generated when Foo is an attribute, or is an element that can occur only once as a child.
Returns or sets the value of Foo as an XMLBean simple type. These methods are generated if Foo's type is defined in schema as a simpleType.
Determines or specifies whether the Foo element is nil (in other words, "null" in schema terms), meaning it can be empty. A nil element looks something like this:
These methods are only generated when an element type is declared as nillable in schema — it has a nillable="true" attribute.
Adds a new Foo as an XMLBean simple to the document, or returns Foo's value if one exists already.
Determines whether the Foo element or attribute exists in the document; removes Foo. These methods are generated for elements and attributes that are optional. In schema, and optional element has an minOccurs attribute set to "0"; an optional attribute has a use attribute set to "optional".
Multiple Occurrence Methods
Methods generated for elements that allow multiple occurrences.
An element may occur multiple times if it has a maxOccurs attribute set to "unbounded" or greater than 1. Attributes can't occur multiple times.
Returns or sets all of the Foo elements.
Returns or sets the Foo child element at the specified index.
Returns the number of Foo child elements.
Removes the Foo child element at the specified index.
Returns or sets all of the Foo elements as XMLBeans simple types.
Generated only when the Foo element is defined as a simple type.
Returns or sets the Foo element at the specified index, using an XMLBeans simple type value.
Generated for an element defined as a simple type in schema.
Inserts a new Foo at the specified index
... returning an XMLBeans simple type representing the new element; returns the existing Foo if there's already one at index.
Adds the specified Foo to the end of the list of Foo child elements.
Inserts the specified Foo child element at the specified index.
Adds a new Foo element to the end of the list
... of Foo child elements, returning an XMLBeans simple type representing the newly added element.