Chapter 7. FOR XML


graphics/chic01.gif

Starting in Chapter 4, "Accessing SQL 2000 via HTTP," we introduced the FOR XML extension to SQL Server 2000's Transact-SQL SELECT statement, showing how it could be used to generate XML documents from a relational database. We also went through numerous examples of how to accomplish this transformation. These examples ranged from placing the SQL query directly in an URL to writing a template file to contain the query to execute.

The FOR XML extension also has an XML mode category that we used by specifying FOR XML AUTO, which generated an attribute-centric XML document. I mentioned then that there are additional parameters to the FOR XML directive, and we'll talk about them now in this chapter.

One of the additional modes we'll cover in this chapter, the EXPLICIT mode, is one of the more difficult and complicated subjects we'll cover in this book.

Many of the examples in this chapter utilize the Query Analyzer. By default, the column size of returned results is limited to a 256-character width. This is too small for some of the XDR schema results that are returned in the examples. To enlarge the width, open the Query Analyzer, select Tools, and then select Options. Click the Results tab. Change Maximum Characters Per Column to a larger number (say, 2,000) and you should be okay (see Figure 7.1).

Figure 7.1. Changing the results column width.

graphics/07fig01.gif

This chapter will cover the following topics:

  • The limitations of the FOR XML extension

  • FOR XML RAW mode and what it accomplishes

  • FOR XML AUTO mode and what it accomplishes

  • FOR XML EXPLICIT mode and why it is the most complicated of the modes

  • Overflow data fields and how to use and manipulate them



XML and SQL Server 2000
XML and SQL Server 2000
ISBN: 0735711127
EAN: 2147483647
Year: 2005
Pages: 104
Authors: John Griffin

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net