Specifying a Target Namespace Using sql:target-namespace
The sql:target-namespace annotation can be used to place elements and attributes from the default namespace into a different namespace. The sql:target-namespace attribute can be added only to the <Schema> tag in the XDR schema.
The value of sql:target-namespace is the namespace URI (Uniform Resource Identifier) to be used for generating elements and attributes specified in the mapping schema. This URI is applied to all elements and attributes in the default namespace. The XML document returned from queries against this schema contain xmlns:prefix="uri" declarations and prefix the element and attribute names accordingly. The URI that is used comes from the value of the sql:target-namespace annotation. However, the prefix is generated arbitrarily and does not correspond to any values in the schema (even if the prefixes are used in the schema).
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 a target namespace
In this example, sql:target-namespace annotation is used to specify the target namespace. As a result, all the elements and attributes that would have gone to the default namespace are redirected to the target namespace (MyNamespace).
<?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"
sql:target-namespace="urn:MyNamespace">
<ElementType name="Orders" >
<AttributeType name="OrderID" />
<attribute type="OrderID"/>
</ElementType>
<ElementType name="Customers" >
<AttributeType name="CustomerID" />
<attribute type="CustomerID" />
<AttributeType name="Contact" />
<attribute type="Contact" sql:field="ContactName" />
<element type="Orders" >
<sql:relationship
key="CustomerID"
foreign-key="CustomerID"
key-relation="Customers"
foreign-relation="Orders" />
</element>
</ElementType>
</Schema>
See Also
IIS Virtual Directory Management for SQL Server