Hierarchical-Formatted XML Document Support

The XML driver can be configured so that it supports hierarchical-formatted documents. In this case, the driver assumes that the document that it is accessing can contain more than one table. The driver scans the document to locate all tables; the available tables are visible through a SQLTables operation. Then, the driver does a second scan to gather each table's column information and to determine a data type for each column.

Let's look at an example of a hierarchical document and discuss the results.

<?xml version="1.0"?> 
  <purchaseOrder orderDate="1999-10-20"> 
    <shipTo country="US"> 
      <name>Alice Smith</name> 
      <street>123 Maple Street</street> 
      <city>Mill Valley</city> 
      <state>CA</state> 
      <zip>90952</zip> 
    </shipTo> 
    <billTo country="US"> 
       <name>Robert Smith</name> 
       <street>8 Oak Avenue</street> 
       <city>Old Town</city> 
       <state>PA</state> 
       <zip>95819</zip> 
    </billTo> 
    <comment>Hurry, my lawn is going wild!</comment> 
    <items> 
       <item partNum="872-AA"> 
          <productName>Lawnmower</productName> 
          <quantity>1</quantity> 
          <USPrice>148.95</USPrice> 
          <comment>Confirm this is electric</comment> 
       </item> 
       <item partNum="926-AA"> 
          <productName>Baby Monitor</productName> 
          <quantity>1</quantity> 
          <USPrice>39.98</USPrice> 
          <shipDate>1999-05-21</shipDate> 
       </item> 
    </items> 
  </purchaseOrder> 

First, the XML driver returns two tables: "purchaseOrder" and "items." Two tables are returned because two items are found for a single purchase order. The XML driver found commonality of child elements.

Second, the XML driver determines which columns are in a specific table. An _ID column, which is essentially a primary key, is automatically generated for each table. If a table is determined to be a child of another table, then it is given a second generated column. The name of this column is prefixed with the parent table's name and ends with _ID, for example, _purchaseOrder_ID.

Consider the previous example document. The items table will receive two generated columns, _ID and _purchaseOrder_ID, which are assigned an integer data type. The purchaseOrder table receives only the _ID column, because it does not have a parent table.

The tables returned from the example file include the following columns:

Table
Columns
items
_ID
_purchaseOrder_ID
partNum
productName
quantity
USPrice
comment
shipDate
purchaseOrder
_ID
orderDate
shipTo_country
shipTo_name
shipTo_street
shipTo_city
shipTo_state
shipTo_zip
billTo_country
billTo_name
billTo_street
billTo_city
billTo_state
billTo_zip
comment

Column Data Types

The XML driver determines the column data types by inspecting the column values. The data type determination limits its data types to a subset of the DataDirect Format data types, as listed in the following table. For a complete list of DataDirect Format data types, see Table 14-5.

Data Type
Sample Values
wvchar
"Foo", "best320"
varbinary
"27AB2F9C"
int
"34","-7000"
unsignedint
"0", "123456789"
long
"-12345678012345"
unsignedlong
"123456789012345"
boolean
"true", "false"
date
1963-12-19
time
10:09:58
timeinstant
1963-12-19T10:09:58
decimal
1245.678