|Products | Download | Buy | About Us|
|Connect XML-2-DB User's Guide|
5(l). XML Propagation Rule - <xml-propagation-rule>
Suppose that we have the following XML data file.
<customer-purchases> <customer first-name="Bill" last-name="Smith"> <software-sale name="ABC Software" purchase-price="120.00" purchase-date="12/20/2001" sales-agent="Patrick"/> <software-sale name="DZ Software" purchase-price="2200.00" purchase-date="12/22/2001" sales-agent="Patrick"/> </customer> <customer first-name="John" last-name="Bush"> <software-sale name="DZ Software" purchase-price="2000.00" purchase-date="10/10/2002" sales-agent="Jane"/> <software-sale name="Quicken" purchase-price="150.00" purchase-date="10/12/2002" sales-agent="Jane"/> <software-sale name="Turbo Tax" purchase-price="50.00" purchase-date="10/10/2002" sales-agent="Jane"/> </customer> </customer-purchases>
This file indicates that Bill Smith purchased 2 pieces of software - ABC Software and DZ software. Also, John Smith purchased 3 pieces of software - DZ Software, Quicken and Turbo Tax. The customer first-name and last-name along with the software name, purchase-price, purchase-date and sales-agent have to be inserted into SOFTWARE_SALES table. If an insertion-map rule is defined that maps the element <customer> to the table SOFTWARE_SALES, only 2 records will be inserted into SOFTWARE_SALES. There should be 5 sales records inserted. The element <software-sale> should be mapped to SOFTWARE_SALES in order to insert the correct number of records. However, neither software-sale nor any of its sub-elements have the customer first and last name. In such a case, we want the customer first-name and last-name to apply to all subsequent software-sale sub-elements of customer. This is done by using the XML propagation rule. The format of the XML propagation rule is as follows:
<!ELEMENT xml-propagation-rule (xml-link+)> <!ATTLIST xml-propagation-rule parent-element CDATA #REQUIRED child-element CDATA #REQUIRED> <!ELEMENT xml-link EMPTY> <!ATTLIST xml-link parent-attribute-name CDATA #IMPLIED child-attribute-name CDATA #IMPLIED>
For the example listed above, the xml-propagation-rule would be:
<xml-propagation-rule parent-element="customer" child-element="software-sale"> <link parent-attribute-name="first-name" child-attribute-name="customer-first-name"/> <link parent-attribute-name="last-name" child-attribute-name="customer-last-name"/> </xml-propagation-rule>
This rule indicates that the Connect XML-2-DB tool will assume that the customer-first-name attribute of software-sale sub-elements of a customer element, will be assigned the same value as the attribute first-name of customer. In other words the first-name and last-name attributes of a customer element are propagated to the customer-first-name and customer-last-name attributes of all software-sale subelements of customer.
An insertion map rule that maps software-sale to SOFTWARE_SALES can now be defined. In addition with the following mapping rule, the correct information will be stored in the SOFTWARE_SALES table.
<insertion-map element-name="software-sale" table-reference="SoftwareSales"/> <map element-name="software-sale" attribute-name="customer-first-name" table-reference="SoftwareSales" column-name="FIRST_NAME"/> <map element-name="software-sale" attribute-name="customer-last-name" table-reference="SoftwareSales" column-name="LAST_NAME"/>
|Copyright © Skyhawk
Systems. All Rights Reserved.
Send comments and questions to firstname.lastname@example.org.