-->
Applies to: SQL Server (all supported versions)
Oxygen XML Developer is the industry-leading XML development tool that includes everything you need for designing XML schemas and transformation pipelines. It focuses on XML source editing, schema design, and the XSLT and XQuery support is enhanced with. XML is the most powerful data storage and transfer medium on the web. It works as XML Viewer, XML Formatter, XML Editor,XML Validator. What can you do with XML Viewer/ XML Formatter? It helps to beautify/format your XML. It helps to display your XML in a tree view. This also works as XML Pretty Print. It helps to minify your XML.
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.
Note
To view Transact-SQL syntax for SQL Server 2014 and earlier, see Previous versions documentation.
XQuery
Is a string, an XQuery expression, that queries for XML nodes, such as elements and attributes, in an XML instance.
This section provides examples of using the query() method of the xml data type.
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:
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.
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.
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)