You may receive the error "This document already has a DocumentElement node." - Part IV

This article is in continuation with Part I, Part II & Part III of the series related to solving the error "This document already has a DocumentElement node." which arises when we try to use XmlReader or an XmlDocument to load the XML Data returned by the FOR XML SQL Query.

The FOR XML EXPLICIT is one of the toughest techniques in returning XML Data from SQL Server using FOR XML. But it also has the greatest flexibility in controlling the XML Format that is being returned contrary to the XML Fragment format that gets returned with FOR XML RAW / FOR XML AUTO queries.

The EXPLICIT modes depends on the concept of Universal Table and manual creation of the XML Structure such that it is returned as such and not simply as a record set.

An introductory article on using FOR XML EXPLICIT is available at

A step-by-step detailed article on returning a hierarchial parent-tree relationship XML from SQL Server is available at
Windows IT Pro - XML Trees - Step by Step

I felt that the above articles cover the indepth of the subject matter and hence didnt go into the explanation of the same over here.

This ends the series of articles on working with XML Fragment data returned by FOR XML Queries and utilizing them in your applications.

Cheers and Happy Programming !!!

Print | posted on Monday, September 19, 2005 9:02 AM

Comments on this post

No comments posted yet.

Your comment:

 (will show your gravatar)