Data model generation

Before an XPath expression can be processed, the input documents must be represented in the XML data model.

An input XML document is transformed into an instance of the XML data model through a process called XML parsing. Alternatively, you can generate an instance of the XML 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 XPath expression 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 XPath 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 XPath data model is annotated with a dynamic type. The dynamic type specifies a range of values. For example, an attribute named version might have the dynamic type xs:decimal to 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 XPath 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.