PATH Mode

PATH mode is the latest and best addition to the FOR XML syntax. It provides a straightforward way of using a limited XPath syntax to specify the shaping of query-produced XML. It is also a very compact syntax in comparison with some of the other modes, especially EXPLICIT.

Let’s look at how PATH mode works by re-creating the XML produced in Listing 47.9, this time using PATH mode. Listing 47.10 illustrates this mode.

Listing 47.10 Using FOR XML PATH to Simplify an EXPLICIT Query

image

The only difference between Listing 47.10 and Listing 47.9 is that here you aren’t outputting a CDATA section—just a text node for the ScrapReason.Name column. ...

Get Microsoft® SQL Server 2008 R2 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.