Data model generation in XQuery
Before an XQuery expression can be processed, the input documents must be represented in the pureXML data model.
An input XML document is transformed into an instance of the pureXML data model through a process called XML parsing. Alternatively, you can generate an instance of the pureXML data model by using SQL XML constructors, such as XMLELEMENT and XMLATTRIBUTES. These built-in functions enable you to generate XML data from relational data. Likewise, the result of an XQuery expression (an instance of the pureXML data model) can be transformed into an XML representation through a process called XML serialization.
- During XML parsing, the string representation of an XML document is transformed
into an instance of the XQuery model.
Optionally, the XML document can be validated against a specific schema. The parsed data is
represented as a hierarchy of nodes and atomic values. Each atomic value, element node, and
attribute node in the XQuery data
model is annotated with a dynamic type. The dynamic type specifies a range of values. For example,
an attribute named
versionmight have the dynamic typexs:decimalto indicate that the attribute contains a decimal value.Restriction: If the XML document is validated against a schema, Db2 does not keep the type annotation for each node. The data is stored as untyped.
The value of an attribute is represented directly within the attribute node. An attribute node of unknown type is annotated with the dynamic type
xs:untypedAtomic.The value of an element is represented by the children of the element node, which might include text nodes and other element nodes. The dynamic type of an element node indicates how the values in the child text nodes are to be interpreted. All element nodes have the type
xs:untyped.An atomic value of unknown type is annotated with the type
xs:untypedAtomic.If an input document has no schema, the document is not validated. Db2 assigns nodes and atomic values as untyped (xs:untyped or xs:untypedAtomic).
- During serialization, the sequence of nodes and atomic values (the instance of the XQuery data model) is converted into its string representation. The result of serialization does not always represent a well-formed document. In fact, serialization can result in a single atomic value (for example, 17) or a sequence of elements that do not have a common parent.