sql xml modes: raw, auto and path

13
XML Modes: RAW, AUTO and PATH Presentation by Aaron Buma Development DBA

Upload: aaron-buma

Post on 06-Aug-2015

580 views

Category:

Software


3 download

TRANSCRIPT

Page 1: SQL XML Modes: RAW, AUTO and PATH

XML Modes:RAW, AUTO and PATH

Presentation by Aaron BumaDevelopment DBA

Page 2: SQL XML Modes: RAW, AUTO and PATH

Session Overview

•FOR XML Clause

•RAW – Including ROW, ROOT and ELEMENTS•AUTO•PATH – With adding attributes

and nameless fields

Page 3: SQL XML Modes: RAW, AUTO and PATH

FOR XML• Required for using RAW, AUTO, EXPLICIT PATH• Transforms result set into XML in a single result

Page 4: SQL XML Modes: RAW, AUTO and PATH

FOR XML - RAW• Each row is turned into an XML node named “row”• Each column is an attribute

• You can replace “row” with your own name

• To make it well formed, add the “root” element

Page 5: SQL XML Modes: RAW, AUTO and PATH

FOR XML – RAW, continued• If you don’t want column values as attributes use

“ELEMENTS”

Page 6: SQL XML Modes: RAW, AUTO and PATH

DEMO

• XML RAW – with ROW, ROOT and ELEMENTS

Page 7: SQL XML Modes: RAW, AUTO and PATH

FOR XML – AUTO• Similar to RAW, but uses table name/alias vs “row”

• ROW, ROOT and ELEMENTS can be used

Page 8: SQL XML Modes: RAW, AUTO and PATH

DEMO

• XML AUTO

Page 9: SQL XML Modes: RAW, AUTO and PATH

FOR XML – PATH• Like RAW, but data is elements instead of attributes

• ROW, ROOT and ELEMENTS can be used

Page 10: SQL XML Modes: RAW, AUTO and PATH

FOR XML – PATH, continued• With PATH, you can put values in attributes: @alias

• Adding “/” in the column alias forces nesting

Page 11: SQL XML Modes: RAW, AUTO and PATH

FOR XML – PATH, continued• Using ‘*’ puts value as element at that level– It’s a “nameless” field because you are not labling it

Page 12: SQL XML Modes: RAW, AUTO and PATH

DEMO

• XML PATH– Forced nesting– Nameless fields

Page 13: SQL XML Modes: RAW, AUTO and PATH

Questions?

• RAW – Including ROW, ROOT and ELEMENTS• AUTO• PATH – With adding attributes

and nameless fields

Presentation Recording, Slides and Scripts– Available at: http://www.AaronBuma.com