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.
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 ...