Guidelines for Using XPath Queries

XML and Internet Support

XML and Internet Support

Guidelines for Using XPath Queries

Microsoft® SQL Server™ 2000 implements a subset of the World Wide Web Consortium (W3C) XPath specification, which is located at http://www.w3.org/TR/1999/PR-xpath-19991008.html" target=_blank>http://www.w3.org/TR/1999/PR-xpath-19991008.html. The implementation of XPath queries in SQL Server 2000 differs from the W3C specification in these areas:

  • Root queries

    SQL Server 2000 does not support the root query (/). Every XPath query must begin at a top-level <ElementType> in the schema.

  • Reporting errors

    The W3C XPath specification defines no error conditions. XPath queries that fail to select any nodes return an empty node-set. In SQL Server 2000, a query may return many types of error messages. For more information, see Errors in XPath Queries.

  • Document order

    In SQL Server 2000, document order is not always determined. Consequently, numeric predicates and axes that use document order (such as following) are not implemented.

    The lack of document order also means that the string value of a node can be evaluated only when that node maps to a single column in a single row. An element with subelements or an IDREFS or NMTOKENS node cannot be converted to string.

    Note  In some cases, the key-fields annotation or keys from the relationship annotation can result in a deterministic document order. However, this is not the primary use of these annotations For more information, see Identifying Key Columns Using sql:key-fields and Specifying Relationships Using <sql:relationship>.

  • Data types

    SQL Server 2000 has limitations in implementing the XPath string, number, and boolean data types. For more information, see XPath Data Types.

  • Cross-product queries

    SQL Server 2000 does not support cross-product XPath queries, such as Customer[Order/@OrderDate=Order/@ShippedDate]. This query selects all Customers with any Order for which the OrderDate equals the ShippedDate of any Order.

    However, SQL Server 2000 does support queries such as Customer[Order[@OrderDate=@ShippedDate]], which selects Customers with any Order for which the OrderDate equals its ShippedDate.

See Also

Using XPath Queries