19 The XML Driver : Using Hints for Tabular-Formatted XML Documents

Using Hints for Tabular-Formatted XML Documents
The XML driver supports table and row hints. You can specify a table hint, a row hint, or both, when configuring an XML data source or using a connection string.
Table hints should be specified so that they resolve to a single node. If a table hint resolves to a set of nodes, the first node in the set is used as the table node. The context of the table hint is always the root node of the XML document.
Row hints define the "row" element and specify whether the rowset is element-based or attribute-based. If a table hint is supplied, the context of the row node is the node to which the table hint resolves; otherwise, the context is the root node of the XML document. The column mode identifier specifies whether the columns of a row are child nodes or attributes of the row node.
When working with hints, keep in mind that the XML driver assumes that the row nodes are the immediate children of the table node.
If only a table hint is specified, the row nodes are the children of the node to which the hint resolves. It is assumed that all of the child nodes have the same name.
If only a row hint is specified, the table node is the parent of the node to which the hint resolves. If the row hint resolves to a set of nodes, the nodes in that set must all have the same parent.
The column mode identifier has the format:
\column mode
where mode can be one of the following options:
In the following examples, the columns are the children of the row nodes.
Example 1
Table Hint:
Row Hint: //Item
The row nodes are the nodes named Item. The table node is the parent of the row nodes. Use this form only when all of the Item nodes reside under one parent.
If some Item nodes have different parents, use a table hint or a more specific row hint to select the set of Item nodes.
Example 2
Table Hint:
Row Hint: /Bookstore/Books/Item
The row nodes are the nodes named Item. The table node is Books, which is a child of the Bookstore node.
Example 3
Table Hint: /Bookstore/Books
Row Hint:
The table node is Books, which is a child of the Bookstore node. The row nodes are the children of the Books node. It is assumed that all of the child nodes under the Books nodes have the same name. If the child nodes do not all have the same name, the name of the first child node encountered is used as the row node name. In that case, it would be better to specify both a table and row hint.
Example 4
Table Hint: /Bookstore [@location = "Raleigh"]/Books
Row Hint: ./Item
The table node is Books, which is a child of the Bookstore node. Bookstore has a "location" attribute with the value Raleigh. The row nodes are the Item nodes that are children of the Books node.
Column Mode Identifier
The following examples illustrate the use of the optional column mode identifier.
Example 5
Table Hint:
Row Hint: //Item \column attr
The row nodes are named Item. The table node is the parent of the row nodes. The columns are attributes of the row node.
Example 6
Table Hint:
Row Hint: //Item \column child
The row nodes are the nodes named Item. The table node is the parent of the row nodes. The columns are attributes of the row node.