IBM Books

XML Extender Administration and Programming

Creating or editing the DAD file for the mapping scheme

Creating a DAD file is required when using XML collections. A DAD file defines the relationship between XML data and multiple relational tables. The XML Extender uses the DAD file to:

You can use either of two methods to map the data between the XML tables and the DB2 table: SQL mapping and RDB_node mapping:

SQL mapping
Uses an SQL statement element to specify the SQL query for tables and columns that are used to contain the XML data. SQL mapping can be used for composing XML documents, only.

RDB_node mapping
Uses an XML Extender-unique element, Relational Database node, or RDB_node, which specifies tables, columns, conditions, and the order for XML data. RDB_node mapping supports more complex mappings than an SQL statement can provide. RDB_node mapping can be used for both composing and decomposing XML documents.

Both methods of mapping use the XPath data model, which is described in The DAD file.

Before you begin

Composing XML documents with SQL mapping

Use SQL mapping when you are composing XML documents and want to use SQL.

Using the administration wizard

Use the following steps to create a DAD file using XML collection SQL mapping

To create a DAD file for composition using SQL mapping:

Use SQL mapping when you are composing XML documents and you want to use an SQL statement to define the table and columns from which you will derive the data in the XML document.

  1. Set up and start the administration wizard. See Starting the administration wizard for details.
  2. Click Work with DAD files from the LaunchPad window. The Specify a DAD windows is displayed.
  3. Choose whether to edit an existing DAD file or to create a new DAD file.

    To create a new DAD file:

    1. Leave the File name field blank.
    2. From the Type menu, select XML collection SQL mapping.
    3. Click Next to open the Select Validation window.

    To edit an existing DAD file:

    1. Type the DAD file name into the File name field, or click ... to browse for an existing DAD file.
    2. Verify that the wizard recognizes the specified DAD file.
      • If the wizard recognizes the specified DAD file, Next is selectable and XML collection SQL mapping is displayed in the Type field.
      • If the wizard does not recognize the specified DAD file, Next is not selectable. Either retype the DAD file name, or click ... to browse again for an existing DAD file. Correct the values of the entry field until Next is selectable.
    3. Click Next to open the Select Validation window.
  4. In the Select Validation window, choose whether to validate your XML documents with a DTD.
  5. Click Next to open the Specify Text window.
  6. Type the prolog name in the Prolog field, to specify the prolog of the XML document to be composed.
    <?xml version="1.0" ?>
    

    If you are editing an existing DAD, the prolog is automatically displayed in the Prolog field.

  7. Type the document type of the XML document in the Doctype field of the Specify Text window, pointing to the DTD for the XML document. For example:
    ! DOCTYPE DAD SYSTEM "c:\dxx\samples\dtd\getstart.dtd"
    

    If you are editing an existing DAD, the document type is automatically displayed in the Doctype field.

  8. Click Next to open the Specify SQL Statement window.
  9. Type a valid SQL SELECT statement in the SQL statement field. For example:
    SELECT o.order_key, customer_name, customer_email, p.part_key, color, quantity, 
      price, tax, ship_id, date, mode from order_tab o, part_tab p, 
    table (select substr(char(timestamp(generate_unique())),16) 
      as ship_id, date, mode, part_key from ship_tab) s 
          WHERE o.order_key = 1 and 
                p.price > 20000 and 
                p.order_key = o.order_key and 
                s.part_key = p.part_key 
          ORDER BY order_key, part_key, ship_id
     
    

    If you are editing an existing DAD, the SQL statement is automatically displayed in the SQL statement field.

  10. Click Test SQL to test the validity of the SQL statement.
  11. Click Next to open the SQL Mapping window.
  12. Select an element or attribute node to map from by clicking on it in the field on the left of the SQL Mapping window.

    Map the elements and attributes in the XML document to element and attribute nodes that correspond to DB2 data. These nodes provide a path from the XML data to the DB2 data.

  13. Type the name of an output file for the modified DAD file in the File name field of the Specify a DAD window.
  14. Click Finish to return to the LaunchPad window.

From the DB2 command shell

Use SQL mapping notation when you are composing XML document and want to use SQL.

The DAD file is an XML file that you can create using any text editor. The following steps show fragments from the samples appendix, Document access definition files. Please refer to these examples for more comprehensive information and context.

  1. Open a text editor.
  2. Create the DAD header:
    <?xml version="1.0"?> 
    <!DOCTYPE DAD SYSTEM "path\dad.dtd"> --> the path and file name of the DTD 
          for the DAD 
     
    
  3. Insert the <DAD></DAD> tags.
  4. After the <DAD> tag, specify the DTD ID that associates the DAD file with the XML document DTD.
    <dtdid>path\dtd_name.dtd> --> the path and file name 
           of the DTD for your application
    
  5. Specify whether to validate (that is, to use a DTD to ensure that the XML document is a valid XML document). For example:
    <validation>NO</validation>   --> specify YES or NO
    
  6. Use the <Xcollection> element to define the access and storage method as XML collection. The access and storage methods define that the XML document will have content derived from data stored in DB2 tables.
    <Xcollection>
    </Xcollection>
    
  7. Specify one or more SQL statements to query or insert data from or into DB2 tables. See Mapping scheme requirements for guidelines. For example, you specify a single SQL query like in the following example:
     <SQL_stmt> 
       SELECT o.order_key, customer_name, customer_email, p.part_key, color, quantity,
       price, tax, ship_id, date, mode from order_tab o, part_tab p, 
       table (select substr(char(timestamp(generate_unique())),16) 
         as ship_id, date, mode, part_key from ship_tab) s 
             WHERE o.order_key = 1 and 
                   p.price > 20000 and 
                   p.order_key = o.order_key and 
                   s.part_key = p.part_key 
             ORDER BY order_key, part_key, ship_id
     </SQL_stmt> 
    
  8. Add the following prolog information:
    <prolog>?xml version="1.0"?</prolog> 
    
    This exact text is required.
  9. Add the <doctype></doctype> tags. For example:
    <doctype>! DOCTYPE Order SYSTEM "c:\dxx\samples\dtd\getstart.dtd"</doctype> 
    
  10. Define the root node using the <root_node></root_node> tags. Inside the root_node, you specify the elements and attributes that make up the XML document.
  11. Map the elements and attributes in the XML document to element and attribute nodes that correspond to DB2 data. These nodes provide a path from the XML data to the DB2 data.
    1. Define an <element_node> for each element in your XML document that maps to a column in a DB2 table.
      <element_node name="name"></element_node>
      

      An element_node can have the following nodes.

      • attribute_node
      • child element_node
      • text_node
    2. Define an <attribute_node> for each attribute in your XML document that maps to a column in a DB2 table. See the example DTDs at the beginning of this section for SQL mapping, as well as the DTD for the DAD file in Appendix A, DTD for the DAD file, which provides the full syntax for the DAD file.

      For example, you need an attribute key for an element <Order>. The value of key is stored in a column PART_KEY.

      DAD file: In the DAD file, create an attribute node for key and indicate the table where the value of 1 is to be stored.

      <attribute_node name="key"> 
          <column name="part_key"/>  
      </attribute_node> 
      

      Composed XML document: The value of key is taken from the PART_KEY column.

      <Order key="1"> 
      
  12. Create a <text_node> for every element or attribute that has content that will be derived from a DB2 table. The text node has a <column> element that specifies from which column the content is provided.

    For example, you might have an XML element <Tax> with a value that will be taken from a column called TAX:

    DAD element:

    <element_node name="Tax"> 
       <text_node> 
       <column name="tax"/> 
       </text_node> 
    </element_node> 
    

    The column name must be in the SQL statement at the beginning of the DAD file.

    Composed XML document:

    <Tax>0.02</Tax>
    

    The value 0.02 will be derived from the column TAX.

  13. Ensure that you have an ending </root_node> tag after the last </element_node> tag.
  14. Ensure that you have an ending </Xcollection> tag after the </root_node> tag.
  15. Ensure that you have an ending </DAD> tag after the </Xcollection> tag.

Composing XML documents with RDB_node mapping

Use RDB_node mapping to compose XML documents using a XML-like structure.

This method uses the <RDB_node> to specify DB2 tables, column, and conditions for an element or attribute node. The <RDB_node> uses the following elements:

The child elements that are used in the <RDB_node> depend on the context of the node and use the following rules:
If the node type is: RDB child element is used:

Table Column Condition1
Root element Y N Y
Attribute Y Y optional
Text Y Y optional
(1) Required with multiple tables

Using the administration wizard

To create a DAD for composition, using RDB_node mapping:

  1. Set up and start the administration wizard. See Starting the administration wizard for details.
  2. Click Work with DAD files from the LaunchPad window. The Specify a DAD window is displayed.
  3. Choose whether to edit an existing DAD file or to create a new DAD.

    To edit an existing DAD:

    1. Type the DAD file name into the File name field or click ... to browse for an existing DAD.
    2. Verify that the wizard recognizes the specified DAD file.
      • If the wizard recognizes the specified DAD file, Next is selectable, and XML collection RDB node mapping is displayed in the Type field.
      • If the wizard does not recognize the specified DAD file, Next is not selectable. Either retype the DAD file name into the File name field or click ... to browse again for an existing DAD file. Continue these steps until Next is selectable.
    3. Click Next to open the Select Validation window.

    To create a new DAD:

    1. Leave the File name field blank.
    2. Select XML collection RDB_node mapping from the Type menu.
    3. Click Next to open the Select Validation window.
  4. In the Select Validation window, choose whether to validate your XML documents with a DTD.
  5. Click Next to open the Specify Text window.
  6. Type the prolog name in the Prolog field of the Specify Text window.
    <?xml version="1.0" ?>
    

    If you are editing an existing DAD, the prolog is automatically displayed in the Prolog field.

  7. Enter the document type of the XML document in the Doctype field of the Specify Text window.

    If you are editing an existing DAD, the document type is automatically displayed in the Doctype field.

  8. Click Next to open the RDB Mapping window.
  9. Select an element or attribute node to map from by clicking on it in the field on the left of the RDB Mapping window.

    Map the elements and attributes in the XML document to element and attribute nodes which correspond to DB2 data. These nodes provide a path from the XML data to the DB2 data.

  10. To add the root node:
    1. Select the Root icon.
    2. Click New Element to define a new node.
    3. In the Details box, specify Node type as Element.
    4. Enter the name of the top level node in the Node name field.
    5. Click Add to create the new node.

      You have create the root node or element, which is the parent to all the other element and attribute nodes in the map. The root node has table child elements and a join condition.

    6. Add table nodes for each table that is part of the collection.
      1. Highlight the root node name and select New Element.
      2. In the Details box, specify Node type as Table.
      3. Select the name of the table from Table name. The table must already exist.
      4. Click Add to add the table node.
      5. Repeat these steps for each table.
    7. Add a join condition for the table nodes.
      1. Highlight the root node name and select New Element.
      2. In the Details box, specify Node type as Condition.
      3. In the Condition field, enter the join condition using the following syntax:.
        table_name.table_column = table_name.table_column AND 
        table_name.table_column = table_name.table_column ...
        
      4. Click Add to add the condition.
  11. To add an element or attribute node:
    1. Click on a parent node in the field on the left to add a child element or attribute.
    2. Click New Element. If you have not selected a parent node, New Element is not selectable.
    3. Select a node type from the Node type menu in the Details box.

      The Node type menu displays only the node types that are valid at that point in the map. Element or Attribute.

    4. Specify a node name in the Node name field.
    5. Click Add to add the new node.
    6. To map the contents of an element or attribute node to a relational table:
      1. Specify a text node.
        1. Click the parent node.
        2. Click New Element.
        3. In the Node type field, select Text.
        4. Select Add to add the node.
      2. Add a table node.
        1. Select the text node you just created and click New Element.
        2. In the Node type field, select Table and specify a table name for the element.
        3. Click Add to add the node.
      3. Add a column node.
        1. Select the text node again and click New Element.
        2. In the Node type field, select Column and specify a column name for the element.
        3. Click Add to add the node.

        Restriction: New columns cannot be created using the administration wizard. If you specify Column as the node type, you can only select a column that already exists in your DB2 database.

      4. Optionally add a condition for the column.
        1. Select the text node again and click New Element.
        2. In the Node type field, select Condition and the condition with the syntax:
          operator LIKE|<|>|= value
          
        3. Click Add to add the node.
    7. Continue editing the RDB map or click Next to open the Specify a DAD window.
  12. To remove a node:
    1. Click on a node in the field on the left.
    2. Click Remove.
    3. Continue editing the RDB_node map or click Next to open the Specify a DAD window.
  13. Type in an output file name for the modified DAD in the File name field of the Specify a DAD window.
  14. Click Finish to remove the node and return to the LaunchPad window.

From the DB2 command shell

The DAD file is an XML file that you can create using any text editor. The following steps show fragments from the samples appendix, Document access definition files. Please refer to these examples for more comprehensive information and context.

  1. Open a text editor.
  2. Create the DAD header:
    <?xml version="1.0"?> 
    <!DOCTYPE DAD SYSTEM "path\dad.dtd"> --> the path and file name of the DTD 
            for the DAD 
     
    
  3. Insert the <DAD></DAD> tags.
  4. After the <DAD> tag, specify the DTD ID that associates the DAD file with the XML document DTD.
    <dtdid>path\dtd_name.dtd> --> the path and file name of the DTD 
            for your application
    
  5. Specify whether to validate (that is, to use a DTD to ensure that the XML document is a valid XML document). For example:
    <validation>NO</validation>   --> specify YES or NO
    
  6. Use the <Xcollection> element to define the access and storage method as XML collection. The access and storage methods define that the XML data is stored in a collection of DB2 tables.
    <Xcollection>
    </Xcollection>
    
  7. Add the following prolog information:
    <prolog>?xml version="1.0"?</prolog> 
    
    This exact text is required.
  8. Add the <doctype></doctype> tags. For example:
    <doctype>! DOCTYPE Order SYSTEM "c:\dxx\samples\dtd\getstart.dtd"</doctype> 
    
  9. Define the root node using the <root_node>. Inside the root_node, you specify the elements and attributes that make up the XML document.
  10. Map the elements and attributes in the XML document to element and attribute nodes that correspond to DB2 data. These nodes provide a path from the XML data to the DB2 data.
    1. Define a root root element_node. This element_node contains:
      • An RDB_node which specifies table_nodes with a join condition to specify the collection
      • Child elements
      • Attributes
      To specify the table nodes and condition:
      1. Create an RDB_node element: For example:
        <RDB_node>
        </RDB_node>
        
      2. Define a <table_node> for each table that contains data to be included in the XML document. For example, if you have three tables, ORDER_TAB, PART_TAB, and SHIP_TAB, that have column data to be in the document, create a table node for each. For example:
        <RDB_node>
        <table name="ORDER_TAB">
        <table name="PART_TAB">
        <table name="SHIP_TAB"></RDB_node>
        
      3. Optionally, specify a key column for each table when you plan to enable this collection. The key attribute is not normally required for composition; however, when you enable a collection, the DAD file used must support both composition and decomposition. For example:
        <RDB_node>
        <table name="ORDER_TAB" key="order_key"> 
        <table name="PART_TAB" key="part_key">
        <table name="SHIP_TAB" key="date mode">
        </RDB_node>
        
      4. Define a join condition for the tables in the collection. The syntax is
        expression = expression AND 
        expression = expression
        
        For example:
        <RDB_node>
        <table name="ORDER_TAB">
        <table name="PART_TAB">
        <table name="SHIP_TAB">
        <condition>
           order_tab.order_key = part_tab.order_key AND 
           part_tab.part_key = ship_tab.part_key
        </condition>
        </RDB_node>
        
    2. Define an <element_node> tag for each element in your XML document that maps to a column in a DB2 table. For example:
      <element_node name="name">
      </element_node>
      

      An element node can have one of the following types of elements:

      • <text_node>: to specify that the element has content to a DB2 table; the element does not have child elements
      • <attribute_node>: to specify an attribute. Attribute nodes are defined in the next step.

      The text_node contains an <RDB_node> to map content to a DB2 table and column name.

      RDB_nodes are used for bottom-level elements that have content to map to a DB2 table. An RDB_node has the following child elements.

      • <table>: defines the table corresponding to the element
      • <column>: defines the column containing the corresponding element and specifies the column type with the type attribute
      • <condition>: optionally specifies a condition on the column

      For example, you might have an XML element <Tax> that maps to a column called TAX:

      XML document:

      <Tax>0.02</Tax>
      

      In this case, you want the value 0.02 to be a value in the column TAX.

      <element_node name="Tax"> 
         <text_node> 
            <RDB_node>
               <table name="part_tab"/>
               <column name="tax"/>
            </RDB_node> 
         </text_node> 
      </element_node> 
      

      In this example, the <RDB_node> specifies that the value of the <Tax> element is a text value, the data is stored in the PART_TAB table in the TAX column.See the example DAD files in Document access definition files for RDB_node mapping, as well as the DTD for the DAD file in Appendix A, DTD for the DAD file, which provides the full syntax for the DAD file.

    3. Optionally, add a type attribute to each <column> element when you plan to enable this collection. The type attribute is not normally required for composition; however, when you enable a collection, the DAD file used must support both composition and decomposition. For example:
      <column name="tax" type="real"/>
      
    4. Define an <attribute_node> for each attribute in your XML document that maps to a column in a DB2 table. For example:
      <attribute_node name="key">
      </attribute_node>
      

      The attribute_node has an <RDB_node> to map the attribute value to a DB2 table and column. An <RDB_node> has the following child elements.

      • <table>: defines the table corresponding to the element
      • <column>: defines the column containing the corresponding element
      • <condition>: optionally specifies a condition on the column

      For example, you might want to have an attribute key for an element <Order>. The value of key needs to be stored in a column PART_KEY. In the DAD file, create an <attribute_node> for key and indicate the table where the value is to be stored.

      DAD file

      <attribute_node name="key"> 
        <RDB_node>
          <table name="part_tab">
          <column name="part_key"/>  
        <RDB_node>
      </attribute_node> 
      

      Composed XML document:

      <Order key="1"> 
      
  11. Ensure that you have an ending </root_node> tag after the last </element_node> tag.
  12. Ensure that you have an ending </Xcollection> tag after the </root_node> tag.
  13. Ensure that you have an ending </DAD> tag after the </Xcollection> tag.

Decomposing XML documents with RDB_node mapping

Use RDB_node mapping to decompose XML documents. This method uses the <RDB_node> to specify DB2 tables, column, and conditions for an element or attribute node. The <RDB_node> uses the following elements:

The child elements that are used in the <RDB_node> depend on the context of the node and use the following rules:
If the node type is: RDB child element is used:

Table Column Condition1
Root element Y N Y
Attribute Y Y optional
Text Y Y optional
(1) Required with multiple tables

Using the administration wizard

To create a DAD for decomposition:

  1. Set up and start the administration wizard. See Starting the administration wizard for details.
  2. Click Work with DAD files from the LaunchPad window. The Specify a DAD windows is displayed.
  3. Choose whether to edit an existing DAD file or to create a new DAD.

    To edit an existing DAD:

    1. Type the DAD file name into the File name field or click ... to browse for an existing DAD.
    2. Verify that the wizard recognizes the specified DAD file.
      • If the wizard recognizes the specified DAD file, Next is selectable, and XML collection RDB node mapping is displayed in the Type field.
      • If the wizard does not recognize the specified DAD file, Next is not selectable. Either retype the DAD file name into the File name field or click ... to browse again for an existing DAD file. Continue these steps until Next is selectable.
    3. Click Next to open the Select Validation window.

    To create a new DAD:

    1. Leave the File name field blank.
    2. Select XML collection RDB_node mapping from the Type menu.
    3. Click Next to open the Select Validation window.
  4. In the Select Validation window, choose whether to validate your XML documents with a DTD.
  5. Click Next to open the Specify Text window.
  6. If you are decomposing an XML document only, ignore the Prolog field. If you are using the DAD file for both composition and decomposition, type the prolog name in the Prolog field of the Specify Text window. The prolog is not required if you are decomposing XML documents into DB2 data.
    <?xml version="1.0"?>
    

    If you are editing an existing DAD, the prolog is automatically displayed in the Prolog field.

  7. If you are decomposing an XML document only, ignore the Doctype field. If you are using the DAD file for both composition and decomposition, enter the document type of the XML document in the Doctype field

    If you are editing an existing DAD, the document type is automatically displayed in the Doctype field.

  8. Click Next to open the RDB Mapping window.
  9. Select an element or attribute node to map from by clicking on it in the field on the left of the RDB Mapping window.

    Map the elements and attributes in the XML document to element and attribute nodes which correspond to DB2 data. These nodes provide a path from the XML data to the DB2 data.

  10. To add the root node:
    1. Select the Root icon.
    2. Click New Element to define a new node.
    3. In the Details box, specify Node type as Element.
    4. Enter the name of the top level node in the Node name field.
    5. Click Add to create the new node.

      You have created the root node or element, which is the parent to all the other element and attribute nodes in the map. The root node has table child elements and a join condition.

    6. Add table nodes for each table that is part of the collection.
      1. Highlight the root node name and select New Element.
      2. In the Details box, specify Node type as Table.
      3. Select the name of the table from Table name. The table must already exist.
      4. Specify a key column for the table in the Table key field.
      5. Click Add to add the table node.
      6. Repeat these steps for each table.
    7. Add a join condition for the table nodes.
      1. Highlight the root node name and select New Element.
      2. In the Details box, specify Node type as Condition.
      3. In the Condition field, enter the join condition using the following syntax:.
        table_name.table_column = table_name.table_column AND 
        table_name.table_column = table_name.table_column ...
        
      4. Click Add to add the condition.

    You can now add child elements and attributes to this node.

  11. To add an element or attribute node:
    1. Click on a parent node in the field on the left to add a child element or attribute.

      If you have not selected a parent node, New is not selectable.

    2. Click New Element.
    3. Select a node type from the Node type menu in the Details box.

      The Node type menu displays only the node types that are valid at that point in the map. Element or Attribute.

    4. Specify a node name in the Node name field.
    5. Click Add to add the new node.
    6. To map the contents of an element or attribute node to a relational table:
      1. Specify a text node.
        1. Click the parent node.
        2. Click New Element.
        3. In the Node type field, select Text.
        4. Select Add to add the node.
      2. Add a table node.
        1. Select the text node you just created and click New Element.
        2. In the Node type field, select Table and specify a table name for the element.
        3. Click Add to add the node.
      3. Add a column node.
        1. Select the text node again and click New Element.
        2. In the Node type field, select Column and specify a column name for the element.
        3. Specify a base data type for the column in the Type field, to specify what type the column must be to store the untagged data.
        4. Click Add to add the node.

        Restriction: New columns cannot be created using the administration wizard. If you specify Column as the node type, you can only select a column that already exists in your DB2 database.

      4. Optionally add a condition for the column.
        1. Select the text node again and click New Element.
        2. In the Node type field, select Condition and the condition with the syntax:
          operator LIKE|<|>|= value
          
        3. Click Add to add the node.

      You can modify these nodes by selecting the node, change the fields in the Details box, and clicking Change.

    7. Continue editing the RDB map or click Next to open the Specify a DAD window.
  12. To remove a node:
    1. Click on a node in the field on the left.
    2. Click Remove.
    3. Continue editing the RDB_node map or click Next to open the Specify a DAD window.
  13. Type in an output file name for the modified DAD in the File name field of the Specify a DAD window.
  14. Click Finish to remove the node and return to the LaunchPad window.

From the DB2 command shell

The DAD file is an XML file that you can create using any text editor. The following steps show fragments from the samples appendix, Document access definition files. Please refer to these examples for more comprehensive information and context.

  1. Open a text editor.
  2. Create the DAD header:
    <?xml version="1.0"?> 
    <!DOCTYPE DAD SYSTEM "path\dad.dtd"> --> the path and file name of the DTD 
           for the DAD 
     
    
  3. Insert the <DAD></DAD> tags.
  4. After the <DAD> tag, specify the DTD ID that associates the DAD file with the XML document DTD.
    <dtdid>path\dtd_name.dtd> --> the path and file name of the DTD 
           for your application
    
  5. Specify whether to validate (that is, to use a DTD to ensure that the XML document is a valid XML document). For example:
    <validation>NO</validation>   --> specify YES or NO
    
  6. Use the <Xcollection> element to define the access and storage method as XML collection. The access and storage methods define that the XML data is stored in a collection of DB2 tables.
    <Xcollection>
    </Xcollection>
    
  7. Add the following prolog information:
    <prolog>?xml version="1.0"?</prolog> 
    
    This exact text is required.
  8. Add the <doctype></doctype> tags. For example:
    <doctype>! DOCTYPE Order SYSTEM "c:\dxx\samples\dtd\getstart.dtd"</doctype> 
    
  9. Define the root_node using the <root_node></root_node> tags. Inside the root_node, you specify the elements and attributes that make up the XML document.
  10. After the <root_node> tag, map the elements and attributes in the XML document to element and attribute nodes that correspond to DB2 data. These nodes provide a path from the XML data to the DB2 data.
    1. Define a top level, root element_node. This element_node contains:
      • Table nodes with a join condition to specify the collection.
      • Child elements
      • Attributes
      To specify the table nodes and condition:
      1. Create an RDB_node element: For example:
        <RDB_node>
        </RDB_node>
        
      2. Define a <table_node> for each table that contains data to be included in the XML document. For example, if you have three tables, ORDER_TAB, PART_TAB, and SHIP_TAB, that have column data to be in the document, create a table node for each. For example:
        <RDB_node>
        <table name="ORDER_TAB">
        <table name="PART_TAB">
        <table name="SHIP_TAB"></RDB_node>
        
      3. Define a join condition for the tables in the collection. The syntax is
        expression = expression AND 
        expression = expression ...
        
        For example:
        <RDB_node>
        <table name="ORDER_TAB">
        <table name="PART_TAB">
        <table name="SHIP_TAB">
        <condition>
           order_tab.order_key = part_tab.order_key AND 
           part_tab.part_key = ship_tab.part_key
        </condition>
        </RDB_node>
        
      4. Specify a primary key for each table. The primary key consists of a single column or multiple columns, called a composite key. To specify the primary key, add an attribute key to the table element of the RDB_node. The following example defines a primary key for each of the tables in the RDB_node of the root element_node Order:
        <element_node name="Order">
            <RDB_node>
                 <table name="order_tab" key="order_key"/>
                 <table name="part_tab" key="part_key price"/>
                 <table name="ship_tab" key="date mode"/>
                 <condition>
                     order_tab.order_key = part_tab.order_key AND 
                     part_tab.part_key = ship_tab.part_key
                 </condition>
            <RDB_node>
         
        
        The information specified for decomposition is ignored when composing an XML document.

        The key attribute is required for decomposition, and when you enable a collection because the DAD file used must support both composition and decomposition.

    2. Define an <element_node> tag for each element in your XML document that maps to a column in a DB2 table. For example:
      <element_node name="name">
      </element_node>
      

      An element node can have one of the following types of elements:

      • <text_node>: to specify that the element has content to a DB2 table; in this case it does not have child elements.
      • <attribute_node>: to specify an attribute; attribute nodes are defined in the next step
      • child elements

      The text_node contains an RDB_node to map content to a DB2 table and column name.

      RDB_nodes are used for bottom-level elements that have content to map to a DB2 table. An RDB_node has the following child elements.

      • <table>: defines the table corresponding to the element
      • <column>: defines the column containing the corresponding element
      • <condition>: optionally specifies a condition on the column

      For example, you might have an XML element <Tax> for which you want to store the untagged content in a column called TAX:

      XML document:

      <Tax>0.02</Tax>
      

      In this case, you want the value 0.02 to be stored in the column TAX.

      In the DAD file, you specify an <RDB_node> to map the XML element to the DB2 table and column.

      DAD file:

      <element_node name="Tax"> 
         <text_node> 
            <RDB_node>
               <table name="part_tab"/>
               <column name="tax"/>
            </RDB_node> 
         </text_node> 
      </element_node> 
      

      The <RDB_node> specifies that the value of the <Tax> element is a text value, the data is stored in the PART_TAB table in the TAX column.

    3. Define an <attribute_node> for each attribute in your XML document that maps to a column in a DB2 table. For example:
      <attribute_node name="key">
      </attribute_node>
      

      The attribute_node has an RDB_node to map the attribute value to a DB2 table and column. An RDB_node has the following child elements.

      • <table>: defines the table corresponding to the element
      • <column>: defines the column containing the corresponding element
      • <condition>: optionally specifies a condition on the column

      For example, you might have an attribute key for an element <Order>. The value of key needs to be stored in a column PART_KEY.

      XML document:

      <Order key="1"> 
      

      In the DAD file, create an attribute_node for key and indicate the table where the value of 1 is to be stored.

      DAD file:

      <attribute_node name="key"> 
        <RDB_node>
          <table name="part_tab">
          <column name="part_key"/>  
        <RDB_node>
      </attribute_node> 
      
  11. Specify the column type for the RDB_node for each attribute_node and text_node. This ensures the correct data type for each column where the untagged data will be stored. To specify the column types, add the attribute type to the column element. The following example defines the column type as an INTEGER:
    <attribute_node name="key">
        <RDB_node>
            <table name="order_tab"/>
            <column name="order_key" type="integer"/> 
        </RDB_node>
    </attribute_node>
     
    
  12. Ensure that you have an ending </root_node> tag after the last </element_node> tag.
  13. Ensure that you have an ending </Xcollection> tag after the </root_node> tag.
  14. Ensure that you have an ending </DAD> tag after the </Xcollection> tag.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]