Using XQuery to Manage XML with SQL Server 2005
- XQuery Advantages
- Working with XQuery Methods
It has probably taken longer for XML to become a mainstream part of today’s applications than many developers first thought. XML is now becoming more widely used as wireless devices are becoming more secure and with better bandwidth. New technologies such as XQuery for SQL Server 2005 is making it much easier to convert relational data to XML and then query the XML data, much as you would relational data, because XQuery is a query language very similar to the SQL query language for relational data. This article gives you a crash course on becoming familiar with XQuery methods and how you can use them in certain situations to retrieve and update XML data stored in your SQL05 database. These methods also contain functions and operators that I’ll touch on a bit with a few examples where necessary. These functions and operators and the combinations that can be used are extensive and can cover the scope of the entire book.
Microsoft originally included XQuery in the .NET framework for use with client-side XML processing. They have since removed it from the .NET framework and kept XQuery native only to the SQL Server environment. The reasons for this vary from being more secure to better performance by having it at the SQL Server level. The .NET framework does still include XML client-side parsing capability through the use of the Systems.XML namespace, however. This namespace includes Xpath 2.0, a language for locating and extracting parts of an XML document. XQuery can also use Xpath expressions.
The advantage of using XQuery 1.0 over XLST, another XML parsing language, is considerably less code and that means fewer maintenance costs according to Microsoft. The queries also have better performance than XLST when parsing a strongly typed XML document because XQuery can be used as a strongly typed language.
Because XQuery is in the process of becoming a W3C standard, XQuery tools are and will be available with many different software packages from many different vendors, not just Microsoft products.