Michael Rys

Musings on XML, XQuery and more...

<September 2008>
SuMoTuWeThFrSa
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011


Navigation

Papers

SQL Server XML Whitepapers

Weblogging Links

MS Bloggers

Recommended Books

Other Blogs

Recommended Links

Presentations (Upcoming)

Presentations (Recent)

Subscriptions

News


Upcoming Presentations


TechEd 2007, Orlando, June 4 to June 8, 2007


Books I co-authored



www.flickr.com
This is a Flickr badge showing public photos from Michael Rys. Make your own badge here.
eXTReMe Tracker

Post Categories

Article Categories



FOR XML Explicit or the "Query from Hell" in Yukon: A less likely encounter

Let me try to start a discussion about FOR XML's most complex, feared, but also useful mode: the EXPLICIT mode.

When we designed the EXPLICIT mode, our goals were:

1. To provide a rowset format that could be mapped into almost any XML shape but also could be formulated by a single SQL query.

2. The rowset format was also supposed to be streamable to allow the generation of large documents.

I think the EXPLICIT mode format is highly successful in achieving these goals. There are only a few things it cannot do (arbitrary recursive part-list trees is one of them). However, the preferred SQL expression to generate the rowset format is a formidable “query from hell”. As one of the designers of the rowset format, I have all the respect for people that write and then maintain multi-thousand line EXPLICIT mode queries. But I also understand the usability, maintainability and complexity issues.

In Yukon starting with Beta1, but even more so in the upcoming Beta2, we are now planning on giving people an alternative. In Beta1, we provide you the ability to nest FOR XML queries. So if you need to generate hierarchies, you now can use nested FOR XML expressions (use the TYPE directive though to get XML). In Beta2, we will provide a new PATH mode that will give you even the ability to map columns in the same selection to attributes, elements, text nodes or even complex properties.

There will still be a few cases, where you may want to use the EXPLICIT mode (in order to generate CDATA sections or to use the !xmltext directive), but the ability to nest FOR XML AUTO, RAW and in Beta2 also PATH modes, should make the “query from hell” a much less frequent encounter.

So if you have the Beta 1 or PDC bits, I would like to encourage you to rewrite some of your EXPLICIT mode queries into nested FOR XML queries and send me some feedback. And also look at the PATH mode once it becomes available. I am especially interested in the following types of feedback: performance improvements or losses, missing functionality (no, we will not add a CDATA section generation to the PATH mode) and any other positive or negative feedback.

And yes, I know that I am writing about not yet fully publicly released software. So as punishment, feel free to send me your EXPLICIT mode issues as well :-). Although, as I mentioned in an earlier Blog entry, such questions may be better posted to SQL Server's XML newsgroup.

posted on Tuesday, January 27, 2004 8:15 PM by mrys


# Take Out: The Daily Doggy Bag of Blog Bits for 29 Jan 2004 @ Wednesday, January 28, 2004 7:22 PM

mrys

# Moving FOR XML EXPLICIT to the new PATH mode @ Thursday, February 19, 2004 2:18 PM

Moving FOR XML EXPLICIT to the new PATH mode

mrys

# Posts on FOR XML @ Wednesday, June 09, 2004 12:21 AM

mrys

# Posts on FOR XML @ Thursday, June 10, 2004 7:34 PM

mrys

# re: FOR XML Explicit or the &amp;quot;Query from Hell&amp;quot; in Yukon: A less likely encounter @ Wednesday, January 24, 2007 1:01 PM

Can't rewrite anything because I need CDATA sections. Also can't next any xml if any of the sections need cdata. As soon as you do a TYPE on explict the cdata specification dissapears.

Chuck

# re: FOR XML Explicit or the &quot;Query from Hell&quot; in Yukon: A less likely encounter @ Tuesday, January 30, 2007 11:46 AM

Hi Chuck

Can you please explain why you need CDATA sections?

CDATA sections are a short cut in XML to allow you to type <>&"' without the need to entitze them everytime you type them. The XML data model (such as the Infoset or XQuery/XPath datamodel) do not make a difference or preserve a CDATA section marker as such. The content just becomes text. That's why the type directive loses the CDATA section markers.

mrys




Powered by Dot Net Junkies, by Telligent Systems