XML and the SQL 2000 Server part 3: XML Data with XPath Queries - Xpath Queries
(Page 2 of 8 )
The XML View allows production of XML content from relational data and queries of relational data as if it were XML, without converting it to XML. XML view is an XML document with additional information added to it called the annotations. This is a construct that allows the SQL Server to determine the tables to use when presented with an Xpath query that uses the XDR Schema. Microsoft's XDR schema is a subset of the more comprehensive w3c's XPath specification [XDR antedates W3C's version]. In the previous article, I showed that of all the T-SQL extensions, the for xml Explicit provides by far the finest control over the XML produced. However, creating for xml explicit queries is not straight forward, and that is where XDR annotated schemas comes to the rescue. Xpath query is not supported directly by the SQL 2000 Server, but using the OleDB Provider. The OleDB Provider converts XPath queries into SQL statements and appends the forXML Explicit clause to them. SQL Server 2000 operates on this SQL formatted statements.
In XPath queries, Tables and views in SQL Server are represented(mapped to) as <elements> and Columns as "attributes" of the <elements>. The annotations mentioned earlier are the mappings between relational database objects to the XML documents. The next picture shows a table stored in the relational database. The picture that follows is the XML view of the same table created using the XML View Mapper. The XML View Mapper will be discussed in detail later in the tutorial. The authors table is mapped to the <ElementType> with name attribute set to the name of the table, namely authors. The various column names are mapped to the different attributes with the Data Type in the table mapped to dt:type in the XML View. Column names go over to AttributeType names exactly. This is implied mapping-when the SQL item and the XDR item have the same name.
| Table Design |
|---|
 |
| |
| XML View |
|---|
 |
Example with Two Tables Having A Relationship
This next picture shows two tables previously considered in parts 1 and 2 of this series. The picture that follows is the XMLView created using the XML View Mapper. Some features of the XDR Schema and the relationship of the relational tables to vis-a-vis the XML View will be explained.

Next: XDR Schema and XML View Mapper >>
More MS SQL Server Articles
More By Jayaram Krishnaswamy