This section provides the following information on how the XML
data handler converts XML documents to business objects:
The XML data handler makes the following assumptions about an
XML document:
- The XML document is well formed.
- The XML document is compliant with SAX parser requirements.
Note that the default parser used by the XML data handler requires
that an XML document include an XML declaration.
- The structure of an XML document must match the structure of
its corresponding business object. In addition, the order of the
elements in the document must match the order of the attributes in
the business object.
When converting an XML document into a business object, the XML
data handler assumes that the business object follows the structure
of the XML document and conforms to the business object definition
requirements described in Requirements for business object
definitions. If there is no attribute in the business object
for a given element name, the XML data handler returns an
error.
To convert an XML document to a business object, the XML data
handler does the following:
- If the calling connector passes in a business object to the
conversion method, the data handler uses this business object and
continues. If the caller does not pass in a business object,
the data handler determines the business object name and creates a
business object to contain the data in the XML document.
To determine the business object name, the data handler invokes
the name handler. The default name handler forms the
top-level business object name by combining the BOPrefix meta-object attribute, an
underscore, and the value of the root element. For example, if the
XML document contains <!DOCTYPE Customer >
and the BOPrefix attribute is MyApp, the
resulting name is MyApp_Customer. You can provide a custom
name handler to configure different behavior.
- The data handler retrieves the value of the Parser meta-object attribute to
determine which SAX parser to
use to parse the XML document.
For information on which SAX parser the XML data handler uses, see
SAX parser. When the
data handler determines the name of the parser, it instantiates the
parser.
- The data handler registers the event handler (for a DTD-based
XML document, it also registers the entity resolver) with the parser. The event handler
is a callback method that processes each XML element and attribute.
- Note:
- The entity resolver handles
external entity references in DTD documents. If the data handler
does not find an
EntityResolver option with a valid class name, it uses
com.crossworlds.DataHandlers.xml.DefaultEntityResolver.
This entity resolver ignores all external references.
- The data handler invokes the parser to parse the XML document.
- The data handler determines if there are any child meta-objects
(those whose names are listed in the cw_mo_label tag of the business object
application-specific information). The data handler does not
perform the processing to populate these attributes of the business
object.
- Depending on the type of element, the parser's event handler
queries the business object definition for the attribute properties
and processes element data accordingly. Execution is stopped only
on fatal errors from the parser or when an element in the XML data
cannot be found in the business object definition.
- When the business object is complete, the data handler returns
it to the caller.
- Note:
- For every element and attribute found in an XML document, the
data handler expects to find an attribute in the business object.
If there is no attribute in the business object definition for a
given element or attribute name, the data handler returns an error.
The exception to this rule is for attributes of type FIXED, which
are not required in a business object definition. If FIXED attributes are not present in the
business object definition, execution does not stop if a FIXED
attribute is found in the XML document.
