The Flags Parameter

OPENXML()'s flags parameter allows you to specify whether OPENXML() should process the document in an attribute-centric fashion, an element-centric fashion, or some combination of the two. Thus far, we've been specifying 2 for the flags parameter, which specifies element-centric mapping. Here's an example of attribute-centric mapping:

 DECLARE @hDoc int EXEC sp_xml_preparedocument @hDoc output, '<songs> <artist name="Johnny Hartman"> <song name="It Was Almost Like a Song"/> <song name="I See Your Face Before Me"/> <song name="For All We Know"/> <song name="Easy Living"/> </artist> <artist name="Harry Connick, Jr."> <song name="Sonny Cried"/> <song name="A Nightingale Sang in Berkeley Square"/> <song name="Heavenly"/> <song ...

Get Guru's Guide to SQL Server™ Stored Procedures, XML, and HTML, 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.