Chapter 7: Querying and Managing XML Data Flashcards
What’s the difference between attributes - centric and element - centric?
The former: , and the latter:
Alfonso
Which clause I need to use for convert a query result to a XML?
FOR XML clause.
What’s the difference between FOR XML RAW and FOR XML AUTO?
Using the RAW version, retrieves a XML without formatting, whereas AUTO version formats by using heuristics.
How I can generate a XML from a result set?
Just by adding the clause FOR XML {RAW | AUTO | EXPLICIT | PATH} at the bottom of the query.
When using FOR XML AUTO, how the XML looks like?
Each row will be mapped as an node, and the columns will be mapped as node’s attributes (not elements; the elements are those node’s children). In case the column is a XML data type, then it’ll be treated as a node child.
How I can create a XML that his children are elements, not attributes?
By using the subclause ELEMENTS after using FOR XML AUTO. For example: FOR XML AUTO, ELEMENTS.
Can I combine node’s attributes with node’s elements?
Yes, it’s possible. Instead of using FOR XML AUTO, use FOR XML PATH, and ensure to alias the column with “@” symbol. For example: OrderId AS ‘@OrderId’