
Example of an Annotated XSD Schema
In the following example, the XSD schema consists of an <Person.Contact> element. The <Employee> element has a ContactID attribute and <FirstName> and <LastName> child elements:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Contact" >
<xsd:complexType>
<xsd:sequence>
<xsd:element name="FName"
type="xsd:string" />
<xsd:element name="LName"
type="xsd:string" />
</xsd:sequence>
<xsd:attribute name="ConID" type="xsd:integer" />
</xsd:complexType>
</xsd:element>
</xsd:schema>
Annotations are added to this XSD schema to map its elements and attributes to the database tables and columns:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
<xsd:element name="Contact" sql:relation="Person.Contact" >
<xsd:complexType>
<xsd:sequence>
<xsd:element name="FName"
sql:field="FirstName"
type="xsd:string" />
<xsd:element name="LName"
sql:field="LastName"
type="xsd:string" />
</xsd:sequence>
<xsd:attribute name="ConID"
sql:field="ContactID"
type="xsd:integer" />
</xsd:complexType>
</xsd:element>
</xsd:schema>
In the mapping schema, the <Contact> element is mapped to the Person.Contact table in the sample AdventureWorks database by using the sql:relation annotation. The attributes ConID, FName, and LName are mapped to the ContactID, FirstName, and LastName columns in the Person.Contact table by using the sql:field annotations.
This annotated XSD schema provides the XML view of the relational data. This XML view can be queried using the XPath language. An XPath query returns an XML document as a result, instead of the rowset that is returned by SQL queries.
Note: |
|---|
|
In the mapping schema, case-sensitivity for the specified relational values (such as table name and column name) depends upon if SQL Server is using case-sensitive collation settings. For more information, see Using SQL Collations.
|