FOR XML

Despite MSXML's power and ease of use, SQL Server doesn't leverage MSXML in all of its XML features. It doesn't use it to implement server-side FOR XML queries, for example, even though it's trivial to construct a DOM document programmatically and return it as text. MSXML has facilities that make this quite easy. For example, Listing 18.2 presents a Visual Basic app that executes a query via ADO and constructs a DOM document on-the-fly based on the results it returns.

Listing 18.2.
 Private Sub Command1_Click() Dim xmlDoc As New DOMDocument30 Dim oRootNode As IXMLDOMNode Set oRootNode = xmlDoc.createElement("Root") Set xmlDoc.documentElement = oRootNode Dim oAttr As IXMLDOMAttribute Dim oNode As IXMLDOMNode Dim oConn As New ADODB.Connection ...

Get Guru's Guide to SQL Server Architecture and Internals, The now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.