Using sql:id-prefix
The sql:id-prefix annotation is used to create a valid XML ID, IDREF, or IDREFS attribute.
In an XML document, the values of ID type attributes must be distinct. If there are multiple ID type attributes in an XML document, to ensure that the values of these attributes are distinct, specify the sql:id-prefix attribute for the ID type attributes. sql:id-prefix is also used to create named tokens from numbers. The value specified for sql:id-prefix must be a valid name character.
The sql:id-prefix attribute is used to prepend the values of ID, IDREF, and IDREFS with a string, thereby, making it unique. No checks are made to ensure the validity of the prefixes and the uniqueness of the values of ID, IDREF, or IDREFS.
sql:id-prefix is ignored on attributes that are not of type ID, IDREF, or IDREFS.
Note Each value of the ID, IDREF, and IDREFS attributes is limited to 4,000 characters, including the prefix (if specified).
Examples
To create working samples using these examples, you must create the nwind virtual directory (to access the Northwind database) and a virtual name of template type. For more information about creating the nwind virtual directory, see Creating the nwind Virtual Directory.
In creating working samples in each example, templates are used to specify XPath queries against the mapping XDR schema. There are different ways of using annotated XDR schemas in queries, for example, inline schemas and schemas in the URL. For more information, see Using Annotated XDR Schemas in Queries.
A. Specify sql:id-prefix for an ID type attribute
In this XDR schema, OrderID and EmployeeID attributes are declared as ID type. To ensure that the IDs are unique and valid, sql:id-prefix annotation is specified for these attributes:
<?xml version="1.0" ?>
<Schema xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:dt="urn:schemas-microsoft-com:datatypes"
xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<ElementType name="Order" sql:relation="Orders" sql:key-fields="OrderID">
<AttributeType name="OrderID" dt:type="id" sql:id-prefix="Ord-" />
<AttributeType name="OrderDate" />
<attribute type="OrderID" />
<attribute type="OrderDate" />
</ElementType>
<ElementType name="Employee" sql:relation="Employees">
<AttributeType name="EmployeeID" dt:type="id" />
<AttributeType name="LastName" />
<attribute type="EmployeeID" />
<attribute type="LastName" />
<AttributeType name="OrderList" dt:type="idrefs"
sql:id-prefix="Ord-" />
<attribute type="OrderList" sql:relation="Orders" sql:field="OrderID">
<sql:relationship
key-relation="Employees"
key="EmployeeID"
foreign-relation="Orders"
foreign-key="EmployeeID" />
</attribute>
<element type="Order">
<sql:relationship key-relation="Employees"
key="EmployeeID"
foreign-relation="Orders"
foreign-key="EmployeeID" />
</element>
</ElementType>
</Schema>
See Also
IIS Virtual Directory Management for SQL Server