Chapter 6 Exchanging data with databases supporting XML


Reinforcing mapping with extended attributes

If you want to modify or reinforce the mapping resulting from the XML Builder Wizard, you can define extended attributes for XML objects. Extended attributes are available from the Microsoft SQL Server extended model definition attached to the mapped XML model. If the element and attribute names match with the table and column names, you do not need to define extended attributes for XML objects.

You could generate an annotated schema without a PDM and the XML Builder Wizard, only through extended attributes, but it would not be the easiest way to proceed.

WARNING! 

Caution
The following procedure assumes you have an XML model open in the workspace, targeted with XSD or XDR, mapped with a PDM, and linked to the Microsoft SQL Server extended model definition. (See Mapping XML objects to PDM objects)

Steps To generate an annotated schema by reinforcing mapping with extended attributes:

  1. Double-click an element symbol in the diagram to display its property sheet.
  2. In the Extended Attributes tab, type the name of a database column in the Value column of the field annotation, if you want to map the element with a database column.

    or

    Type the name of a database table in the Value column of the relation annotation, if you want to map the element with a database table.


    You can define a value for the following annotations regarding an element (E) and/or an attribute (A):
    Annotation E A Description
    encode     When an XML element or attribute is mapped to a SQL Server BLOB column, allows requesting a reference (URI) to be returned and used later to return BLOB data
    field     Maps an XML item to a database column
    hide     Hides the element or attribute specified in the schema in the resulting XML document
    is-constant   Creates an XML element that does not map to any table. The element is displayed in the query output
    key-fields   Allows specification of columns that uniquely identify the rows in a table
    limit-field     Allows limiting the values that are returned on the basis of a limiting value
    limit-value     Allows limiting the values that are returned on the basis of a limiting value
    mapped     Allows schema items to be excluded from the result
    max-depth   Allows you to specify depth in recursive relationships that are specified in the schema
    overflow-field   Identifies the database column that contains the overflow data
    relation   Maps an XML item to a database table
    relationship-child   Specifies an element as the child table in a reference (To define only in the child element property sheet)
    relationship-child-key   Specifies an attribute as the foreign key of a child table in a reference (To define only in the child element property sheet)
    relationship-parent   Specifies an element as the parent table in a reference (To define only in the child element property sheet)
    relationship-parent-key   Specifies an attribute as the primary key of a parent table in a reference (To define only in the child element property sheet)
    use-cdata   Allows specifying CDATA sections to be used for certain elements in the XML document
    prefix   Creates valid XML ID, IDREF, and IDREFS. Prepends the values of ID, IDREF, and IDREFS with a string
  3. Click OK.
  4. Repeat steps 1 to 3 for each element or attribute you want to map with a database table or column, or for which you want to define extra annotations.
  5. Select Language→Generate XML Schema Definition File.

    or

    Select Language→Generate XML-Data Reduced File.

    The Generation dialog box is displayed with Microsoft SQL Server selected in the Targets tab.
  6. Click the Select a Path button, beside the Directory box, to select a path for the annotated schema file.
  7. Click OK.

    The Result dialog box is displayed with the path of the annotated schema file selected.
  8. Click Edit.

    The annotated schema is displayed in the editor window.


    Note the SQL namespace (with the sql prefix) and the SQL annotations for tables (sql:relation), columns (sql:field) and reference (sql:relationship).
  9. Click Close in the Result dialog box.

 


Copyright (C) 2007. Sybase Inc. All rights reserved.