Database Reference
In-Depth Information
Observations About XML RAW Formatting
The following are tips about XML RAW :
XML RAW does not provide a root node, which is why the XML structure is not a
well-formed XML document.
Since XML RAW supports attribute- and element-centric formatting, all the columns
must be formatted in the same way. Hence, it is not possible to have an XML
structure returned with both the XML attributes and XML elements.
XML RAW generates a hierarchy where all the elements in the XML structure are at
the same level.
Using FOR XML AUTO
AUTO mode returns query results as nested XML elements. This does not provide much control over the
shape of the XML generated from a query result. As such, AUTO mode queries are useful if you want to
generate simple hierarchies.
Each table in the FROM clause, from which at least one column is listed in the SELECT clause, is
represented as an XML element. The columns listed in the SELECT clause are mapped to attributes or
subelements.
Try It: Using FOR XML AUTO
Let's produce the SQL query result as nested XML elements. FOR XML AUTO is the statement we will use to
produce the output, as you will see in following steps:
1. Replace the existing query in query pane with the following query, and click
Execute:
select Person.Contact.Title, Person.Contact.FirstName, Person.Contact.LastName
from Person.Contact
where Person.Contact.Title ='Mr.'
for xml auto
2. You will see a link in the results pane of the query pane. Click the link, and you
should see the results in Figure 7-4.
 
Search WWH ::




Custom Search