Xml Query Tool

-->

The XML ODBC Driver is a powerful tool that allows you to connect with live XML data stores, directly from any applications that support ODBC connectivity. Access XML data like you would any standard database - read, write, and update etc. Through a standard ODBC Driver interface. The XPath expression in the tool window supports intellisense based on the content XML Editor, and has tools demonstrating the use of the expression in a number of programming environments. Web Service Test Client. This tool allows you to browse a web service, select a web method, call the method and view the results.

Applies to: SQL Server (all supported versions)

Specifies an XQuery against an instance of the xml data type. The result is of xml type. The method returns an instance of untyped XML.

Syntax

Note

To view Transact-SQL syntax for SQL Server 2014 and earlier, see Previous versions documentation.

Arguments

XQuery
Is a string, an XQuery expression, that queries for XML nodes, such as elements and attributes, in an XML instance.

Examples

This section provides examples of using the query() method of the xml data type.

A. Using the query() method against an xml type variable

The following example declares a variable @myDoc of xml type and assigns an XML instance to it. The query() method is then used to specify an XQuery against the document.

The query retrieves the <Features> child element of the <ProductDescription> element:

The following output shows the result:

B. Using the query() method against an XML type column

In the following example, the query() method is used to specify an XQuery against the CatalogDescription column of xml type in the AdventureWorks database:

Xml Query Tool Photoshop

Note the following items from the previous query:

  • The CatalogDescription column is a typed xml column, which means it has a schema collection associated with it. In the XQuery Prolog, the namespace keyword defines the prefix that's later used in the query body.

  • The query() method constructs XML, a <Product> element that has a ProductModelID attribute, in which the ProductModelID attribute value is retrieved from the database. For more information about XML construction, see XML Construction (XQuery).

  • The exist() method (XML data type) in the WHERE clause finds only rows that contain the <Warranty> element in the XML. Again, the namespace keyword defines two namespace prefixes.

The following output shows the partial result:

Note the query() and exist() methods both declare the PD prefix. In these cases, you can use WITH XMLNAMESPACES to first define the prefixes and use it in the query.

See Also

Windows

Add Namespaces to Queries with WITH XMLNAMESPACES
Compare Typed XML to Untyped XML
Create Instances of XML Data
xml Data Type Methods
XML Data Modification Language (XML DML)

-->

Applies to: SQL Server (all supported versions)

Specifies an XQuery against an instance of the xml data type. The result is of xml type. The method returns an instance of untyped XML.

Syntax

Xml query tools

Note

To view Transact-SQL syntax for SQL Server 2014 and earlier, see Previous versions documentation.

Arguments

XQuery
Is a string, an XQuery expression, that queries for XML nodes, such as elements and attributes, in an XML instance.

Xml Query Tools

Examples

Xml query tool

This section provides examples of using the query() method of the xml data type.

A. Using the query() method against an xml type variable

The following example declares a variable @myDoc of xml type and assigns an XML instance to it. The query() method is then used to specify an XQuery against the document.

The query retrieves the <Features> child element of the <ProductDescription> element:

Xml query tool windows

The following output shows the result:

B. Using the query() method against an XML type column

In the following example, the query() method is used to specify an XQuery against the CatalogDescription column of xml type in the AdventureWorks database:

Note the following items from the previous query:

  • The CatalogDescription column is a typed xml column, which means it has a schema collection associated with it. In the XQuery Prolog, the namespace keyword defines the prefix that's later used in the query body.

  • The query() method constructs XML, a <Product> element that has a ProductModelID attribute, in which the ProductModelID attribute value is retrieved from the database. For more information about XML construction, see XML Construction (XQuery).

  • The exist() method (XML data type) in the WHERE clause finds only rows that contain the <Warranty> element in the XML. Again, the namespace keyword defines two namespace prefixes.

Xml Query Tool Download

The following output shows the partial result:

Xml Query Tool Microsoft

Note the query() and exist() methods both declare the PD prefix. In these cases, you can use WITH XMLNAMESPACES to first define the prefixes and use it in the query.

See Also

Add Namespaces to Queries with WITH XMLNAMESPACES
Compare Typed XML to Untyped XML
Create Instances of XML Data
xml Data Type Methods
XML Data Modification Language (XML DML)