xml spy
Previous  Top  Next
Creating Identity constraints

MS Access databases automatically generate Identity constraints when you use the Convert | Create Database Schema command to create a schema.

Defining identity constraints:
The aim of this section is to be able to import XML data based upon a schema, using the Convert | XML Data Import based on DB Schema. This command uses the active schema file as a base for importing data from an external database. The schema file delivers some of the necessary information needed to automatically generate a select statement string.

1.Open the No-constraints.xsd file in the Tutorial folder of XML Spy.  
2.Click the Altova element to select it and click the Identity constraints tab.  
3.Click the Append icon and select the Key entry.  

id_constraints1  

4.Enter Altova-Primary in the Name field and hit the Tab key.  
5.Enter a period character "." in the Selector field and hit the Tab key again.  
6.Enter PrimaryKey in the Field(s) cell and hit Return to confirm.  

id_constraints2  

This has defined the Altova element as the top-level table.  
7.Click the Division element in the schema overview, click the Append icon and select the Keyref entry.  
8.Enter Division-Foreign in the Name field, hit the Tab key and select Altova-Primary from the combo box and hit the Tab key.  

id_constraints3  

9.Enter a period character "." in the Selector field and hit the Tab key again.  
10.Enter ForeignKey in the Field(s) cell and hit Return to confirm.  
11.Click the Append icon and select the Key entry. Use the same method to enter the following data: Name=Division-Primary, Selector=".", and Field(s)=PrimaryKey.  

id_constraints4  

You have now created a relationship between the Altova and Division tables/elements, where the Division table is linked to the Altova table.  

Checking the relationship

1.Select the menu option Convert | XML import based on DB Schema.  
2.Select Altova as the root table in the dialog box that opens.  
This opens the "Database import based on Schema" dialog box. The automatically generated shape string appears in the Select statement text box. The select string shows that the Altova table is related to the Division table.  

id_constraints5  

3.Click the Cancel button to close the dialog box for the moment.  

Completing the identity constraints
We now have to define the rest the remaining identity constraints for the Person and VIP tables (elements in the schema). Use the method outlined above to add Key and Keyref fields to the Person and VIP elements.

Person element:
id_constraints6  

VIP element:
id_constraints7  

Importing data using a schema (with identity constraints)
1.Select the menu option Convert | XML import based on DB Schema.  
2.Select Altova as the root table in the dialog box that opens. (You can choose any one of the entries as the root table, Division, Person or VIP.)  
This opens the "Database import based on Schema" dialog box. The automatically generated shape string appears in the Select statement text box.  
id_constraints8  

3.Click the "Choose file" button, select the DB2schema.mdb file in the Tutorial folder, and click the Open button. This enables the OK button in the Database import... dialog box.  
4.Click the OK button to start the data import.  
The XML document appears as an "Untitledx.xml" file in the main window. Scroll right to see the complete structure.  

mnu_xml_import5a  

Please note:  
If you want to edit the select statement, start a new data import using the menu option Convert | Import database data. The select statement is automatically made available to Select statement text box after having used the Convert | XML Import based on DB Schema. You can now edit the select statement and import the data from here.  

Previous  Top  Next

⌐ 2002 Altova