The generated DAD script
The structure of the generated script can be broken down into 4 sections:
- Declarations
- The dtdid
- Validation
- Xcollection
Declaration
The declaration section:
- Identifies the DAD script as an XML document
- Identifies the DAD element as the root of the XML tree
- Specifies the DTD for the DAD document
In the following code sample...
<?xml version="1.0"?> <!DOCTYPE DAD SYSTEM "/home/dxxinst/dtd/dad.dtd">...<?xml version="1.0"?> is the XML declaration and <!DOCTYPE DAD SYSTEM "/home/dxxinst/dtd/dad.dtd"> is the root of the DAD script, while dxxinst is the DTD for the DAD.
The dtdid
The dtdid points to the DTD that validates the XML documents and guides the mapping between XML collection tables and XML documents. Note that the dtdid must be the same as the SYSTEM ID specified in the doctype of the XML document. The dtdid must always be specified.
For example, the line...
<dtdid>/home/dtd/neworder.dtd</dtdid>...associates the DAD file with the XML target document DTD.
Validation
Indicates whether or not the XML document is to be validated with the DTD for the DAD. In the current version, the generated DAD script always specifies NO for the validation element.
For example, the line...
<validation>NO</validation>..indicates whether or not to validate the XML target document with the specified DTD file.
Xcollection
Xcollection defines the RDB_node mapping between XML documents and an XML collection of relational tables. In essence, it defines the location of the content of an XML element or the value of an XML attribute so that the DB2 XML Extender can determine where to store or retrieve the XML data.
Xcollection has the following child elements:
- prolog
- doctype
- root_node
prolog
<prolog> defines the text for the XML prolog. The same prolog is supplied to all XML documents in the entire collection. The value of prolog is fixed.
For example, the following line:
<prolog>?xml version="1.0"?</prolog>
is the XML declaration for the XML target document
doctype
<doctype> defines the text for the XML document type definition. The same doctype is supplied to all XML documents in the entire collection. Note that the SYSTEM ID specified in the doctype must be the same as that specified in the dtdid.
For example, the following line is the doctype declaration for the XML target document:
<doctype>!DOCTYPE Order SYSTEM "/home/dtd/neworder.dtd"</doctype>
Order is the root element of the XML target document, and neworder.dtd is the DTD corresponding to the XML target document.
root_node
Defines the virtual root node. The single element_node under the root_node (the top element_node) is actually the root node of the XML target document. This top element_node contains:
- An RDB_node which specifies table_nodes with a join condition to specify the collection
- Zero or more child element_nodes
- Zero or more attribute_nodes
RDB_node for top element_node
An RDB_node is required for the top element_node which represents the root element of the XML document. An RDB_node for the top element_node must specify the following:
- All tables that are associated with the XML documents
- (Optional) An orderBy attribute for each table to preserve the order of the document
- A condition, specifying the primary and foreign key relationships as joins to group the tables together
In the current version of the generated DAD script, the orderBy attribute on a table element is not supported. The orderBy attribute allows you to preserve the order of a document containing elements or attributes with multiple occurrence in their original structure.
Consider the following code sample:
<RDB_node> <table name="order_tab"key="order_key1 order_key2 order_key3"/> <table name="part_tab" key="part_key1 part_key2"/> <table name="ship_tab" key="date"/> <condition> order_tab.order_key1=part_tab.o_key1 AND order_tab.order_key2=part_tab.o_key2 AND order_tab.order_key3=part_tab.o_key3 AND part_tab.order._key1=ship_tab.p_key1 AND part_tab.part_key2=ship_tab.p_key2 </condition> </RDB_node>In this sample...
<table name="order_tab" key="order_key1 order_key2 order_key3"/> <table name="part_tab" key="part_key1 part_key2"/> <table name="ship_tab" key="date"/>...are tables that are associated with the XML documents...
key="order_key1 order_key2 order_key3...is a composite primary key...
key="date"...is a primary key, and...
<condition>order_tab.order_key1=part_tab.o_key1 and order_tab.order_key2=part_tab.o_key2 and order_tab.order_key3=part_tab.o_key3 and part_tab.order._key1=part_tab.p_key1 and part_tab.part_key2=ship_tab.p_key1 and </condition>...is the condition statement specifying the primary and foreign key relationships as joins.
element_node
An element_node represents an XML element. It must be defined in the DTD specified for the collection. An element_node (other than the top element_node) contains:
- Zero or more child element_nodes representing child elements of the current XML element
- Zero or more attribute_nodes representing attributes of the current XML element
- Zero or one text_node representing the CDATA text of the current XML element
In the RDB_node mapping scheme, the data resides in the attribute_node and text_node for each element_node. Therefore, there is an RDB_node defined for each attribute_node and text_node, specifying which table and which column to get the data from.
attribute_node
An attribute_node represents an XML attribute. It is the node defining the mapping between an XML attribute and the column data in a relational table. The attribute_node must contain an RDB_node with both a table and column defined.
Consider the following code sample...
<attribute_node name="Key1"> <RDB_node> <table name="order_tab"/> <column name="order_key1" type="integer"/> </RDB_node> </attribute_node>In this sample...
name="Key1"...specifies the name of the attribute
<RDB_node> <table name="order_tab"/> <column name="order_key1" type="integer"/> </RDB_node>...defines the mapping between the attribute and column data...
<table name="order_tab"/>...specifies the name of the relational table where the data resides, and
<column name="order_key1" type="integer"/>...specifies the name and type of the column where the data resides.
text_node
A text_node represents the text content of an XML element. It is the node defining the mapping between XML element content and the column data in a relational table. The text_node must contain an RDB_node with both a table and a column defined.
Consider the following code sample...
<text_node> <RDB_node> <table name="order_tab"/> <column name="customer_name" type="varchar(16)"/> </RDB_node> </text_node>In this sample...
<RDB_node> <table name="order_tab"/> <column name="customer_name" type="varchar(16)"/>...defines the actual mapping between the element content and the column data...
<table name="order_tab"/>...specifies the name of the relational table where the data resides
<column name="customer_name" type="varchar(16)"/>...specifies the name and type of the column where the data resides.
Related concepts
DAD script
Related tasks
Generating DAD files
Editing DAD files
Running DAD files with the DB2 XML Extender