﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Discuss Content Posted by Hugh Lynch / Article Discussions / Article Discussions by Author  / Simplify the Creation of XML from SQL Server Data / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sat, 18 May 2013 23:07:56 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Simplify the Creation of XML from SQL Server Data</title><link>http://www.sqlservercentral.com/Forums/Topic221268-252-1.aspx</link><description>&lt;P&gt;I'm a big fan of wheels - I try to keep a bunch on hand so I'll always have one that fits!&lt;/P&gt;&lt;P&gt;What shapes offer is a way to produce precise, potentially complex XML simply and efficiently using store procs and generic invokers.  One can create a rich, navigable web UI using shapes, XSL and no other code.  The shape tester, using shpList, is a simple example of this.&lt;/P&gt;&lt;P&gt;Shapes also jive nicely with the trend toward background queries from client-side javascript.&lt;/P&gt;&lt;P&gt;Getting your first shape to work requires some non-trivial configuration of the generic components, but once that's done the incremental cost of new shapes is very modest.&lt;/P&gt;&lt;P&gt;-Hugh&lt;/P&gt;</description><pubDate>Wed, 02 Nov 2005 07:41:00 GMT</pubDate><dc:creator>Hugh Lynch</dc:creator></item><item><title>RE: Simplify the Creation of XML from SQL Server Data</title><link>http://www.sqlservercentral.com/Forums/Topic221268-252-1.aspx</link><description>Maybe I am missing something but this solution sounds a little bit like reinvention of the wheel. I typically bypass the XML in my applications by using typed datasets. Technically, this isn't bypassing XML but I don't think in terms of XML when I am using them. A typed dataset can be serialized to XML using the GetXML method (inherited from the DataSet class). If that isn't pretty enough then an XSL transformation should do the trick. I have used this with UI designers that needed XML data in Flash and they were able to work with the DataSet data without any transformation despite minimal programming experience.</description><pubDate>Wed, 02 Nov 2005 06:24:00 GMT</pubDate><dc:creator>Tatsu</dc:creator></item><item><title>RE: Simplify the Creation of XML from SQL Server Data</title><link>http://www.sqlservercentral.com/Forums/Topic221268-252-1.aspx</link><description>&lt;P&gt;Hi Hugh.&lt;/P&gt;&lt;P&gt;Thank you very much for sharing such a wonderful utility with the community.  It is obvious that you have thought a great deal about keeping the output flexible whilst not burdening the developer nor the server.  I look forward to trying it out in the coming weeks (I'm absolutely flooded with work at the moment!).&lt;/P&gt;&lt;P&gt;Cheers!!&lt;/P&gt;</description><pubDate>Tue, 01 Nov 2005 06:33:00 GMT</pubDate><dc:creator>Ian Yates</dc:creator></item><item><title>RE: Simplify the Creation of XML from SQL Server Data</title><link>http://www.sqlservercentral.com/Forums/Topic221268-252-1.aspx</link><description>&lt;P&gt;Hi Hugh,&lt;/P&gt;&lt;P&gt;I'm happy for you to use the FOR XML examples, so long as you give me credit &lt;img src='images/emotions/smile.gif' height='20' width='20' border='0' title='Smile' align='absmiddle'&gt;Good luck with future publishings!&lt;/P&gt;&lt;P&gt;All the best,Ryan&lt;/P&gt;</description><pubDate>Fri, 28 Oct 2005 08:00:00 GMT</pubDate><dc:creator>RyanRandall</dc:creator></item><item><title>RE: Simplify the Creation of XML from SQL Server Data</title><link>http://www.sqlservercentral.com/Forums/Topic221268-252-1.aspx</link><description>&lt;P&gt;For those having trouble getting the download, I also posted it at:&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.hughlynch.com/shapes/RSSWebShapes.zip"&gt;http://www.hughlynch.com/shapes/RSSWebShapes.zip&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I'm not sure what's up with tech.rssgroup.com; unfortunately, it's one of those awkward "works-for-me" situations.  Sorry about the difficulty.&lt;/P&gt;&lt;P&gt;Ryan,&lt;/P&gt;&lt;P&gt;Thanks for the post.  The FOR XML examples are excellent and if you wouldn't mind, I'd like to incorporate them into the article.  I don't know if/when/where it will be published again, but nonetheless...  &lt;/P&gt;&lt;P&gt;The examples make it fairly evident that even at this modest level of complexity, the FOR XML EXPLICIT syntax and construction leave a bit to be desired.  On the other hand, the FOR XML AUTO seems simple enough, but provides very little control.  Neither is much fun to work with in Query Analyzer and both have the property of burdening the database with work that could easily be farmed out.&lt;/P&gt;&lt;P&gt;I'll continue to monitor this thread for those wishing to give shapes a try.&lt;/P&gt;&lt;P&gt;-Hugh&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description><pubDate>Fri, 28 Oct 2005 07:55:00 GMT</pubDate><dc:creator>Hugh Lynch</dc:creator></item><item><title>RE: Simplify the Creation of XML from SQL Server Data</title><link>http://www.sqlservercentral.com/Forums/Topic221268-252-1.aspx</link><description>&lt;P&gt;Good article - thanks Hugh.  A shame about the download, but I'm sure you'll get that fixed. &lt;img src='images/emotions/smile.gif' height='20' width='20' border='0' title='Smile' align='absmiddle'&gt;In case anyone's not familiar with the FOR XML clause, here's how you can get XML results equivalent to the results in the article.  As is so often the case, the method you choose will depend on your requirements, and the method in the article is a very useful one to add to the toolbox.Okay, here we go.  Both of these stored procedure calls...&lt;FONT face="Courier New" color=#3333dd&gt;exec dbo.XmlAuto_EmployeeActivity 6, '1 Jan 1997', '31 Jan 1997'exec dbo.XmlExplicit_EmployeeActivity 6, '1 Jan 1997', '31 Jan 1997'&lt;/FONT&gt;...give...&lt;FONT color=#117711&gt;&amp;lt;Employee EmployeeID="6" LastName="Suyama" FirstName="Michael"&amp;gt;  &amp;lt;Customer CustomerID="GOURL" CompanyName="Gourmet Lanchonetes"&amp;gt;    &amp;lt;Order OrderID="10423" OrderDate="1997-01-23T00:00:00"&amp;gt;      &amp;lt;Item ProductID="31" UnitPrice="10.0000" Quantity="14" Discount="0.0000000e+000"/&amp;gt;      &amp;lt;Item ProductID="59" UnitPrice="44.0000" Quantity="20" Discount="0.0000000e+000"/&amp;gt;    &amp;lt;/Order&amp;gt;  &amp;lt;/Customer&amp;gt;  &amp;lt;Customer CustomerID="LAMAI" CompanyName="La maison d&amp;amp;apos;Asie"&amp;gt;    &amp;lt;Order OrderID="10425" OrderDate="1997-01-24T00:00:00"&amp;gt;      &amp;lt;Item ProductID="55" UnitPrice="19.2000" Quantity="10" Discount="2.5000000e-001"/&amp;gt;      &amp;lt;Item ProductID="76" UnitPrice="14.4000" Quantity="20" Discount="2.5000000e-001"/&amp;gt;    &amp;lt;/Order&amp;gt;  &amp;lt;/Customer&amp;gt;&amp;lt;/Employee&amp;gt;&lt;/FONT&gt;And here's the code for the 2 stored procedures...&lt;FONT face="Courier New" color=#3333dd&gt;create procedure dbo.XmlAuto_EmployeeActivity  @employeeID  int, @startDate   smalldatetime, @endDate     smalldatetime as&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" color=#3333dd&gt;select  Employee.EmployeeID, LastName, FirstName,  Customer.CustomerID, CompanyName,  [Order].OrderID, OrderDate,   ProductID, UnitPrice, Quantity, Discountfrom  Employees as Employee  inner join Orders as [Order] on Employee.EmployeeID = [Order].EmployeeID  inner join Customers as Customer on Customer.CustomerID = [Order].CustomerID  inner join [Order Details] as Item on Item.OrderID = [Order].OrderIDwhere  Employee.EmployeeID = @employeeID and orderDate between @startDate and @endDate&lt;FONT color=#ff1111&gt;for xml auto&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#dd1111&gt;---------------------------------------------------------------------------------------------&lt;/FONT&gt;&lt;FONT face="Courier New" color=#3333dd&gt;create procedure dbo.XmlExplicit_EmployeeActivity  @employeeID  int, @startDate   smalldatetime, @endDate     smalldatetime as&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#3333dd&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#117711&gt;--Put relevant orders into a table variable&lt;/FONT&gt;declare @tblOrders table (OrderID int primary key)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" color=#3333dd&gt;insert @tblOrdersselect orderID from orders where employeeId = @employeeId and orderDate between @startDate and @endDate&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#3333dd&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#117711&gt;--Header&lt;/FONT&gt;select  null as 'tag', null as 'parent', --  null as 'Employee!1!EmployeeID', null as 'Employee!1!LastName', null as 'Employee!1!FirstName', --Employee  null as 'Customer!2!CustomerID', null as 'Customer!2!CompanyName', --Customer  null as 'Order!3!OrderID', null as 'Order!3!OrderDate', --Order  null as 'Item!4!ProductID', null as 'Item!4!UnitPrice', null as 'Item!4!Quantity', null as 'Item!4!Discount' --Itemwhere 0 = 1&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" color=#3333dd&gt;union&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#3333dd&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#117711&gt;--Employee&lt;/FONT&gt;select 1, null, /**/ EmployeeID, LastName, FirstName, /**/ null, null, /**/ null, null, /**/ null, null, null, null from Employees where employeeID = @employeeId&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" color=#3333dd&gt;union&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#3333dd&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#117711&gt;--Customer&lt;/FONT&gt;select 2, 1, /**/ @employeeId, null, null, /**/ CustomerID, CompanyName, /**/ null, null, /**/ null, null, null, null from Customers where customerID in (select customerID from orders where orderID in (select orderID from @tblOrders))&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" color=#3333dd&gt;union&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#3333dd&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#117711&gt;--Order&lt;/FONT&gt;select 3, 2, /**/ @employeeId, null, null, /**/ CustomerID, null, /**/ OrderID, OrderDate, /**/ null, null, null, null from orders where orderID in (select orderID from orders where orderID in (select orderID from @tblOrders))&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" color=#3333dd&gt;union&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#3333dd&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#117711&gt;--Item&lt;/FONT&gt;select 4, 3, /**/ @employeeId, null, null, /**/ CustomerID, null, /**/ d.OrderID, null, /**/ ProductID, UnitPrice, Quantity, Discount from [Order Details] d inner join Orders o on o.orderID = d.orderID where d.orderID in (select orderID from @tblOrders)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" color=#3333dd&gt;order by 'Employee!1!EmployeeID', 'Customer!2!CustomerID', 'Order!3!OrderID', 'Item!4!ProductID'&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#3333dd&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#ff1111&gt;for xml explicit&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#dd1111&gt;---------------------------------------------------------------------------------------------&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#111111&gt;Regards,Ryan&lt;/FONT&gt;&lt;FONT color=#3333dd&gt;&lt;/P&gt;&lt;/FONT&gt;</description><pubDate>Fri, 28 Oct 2005 04:45:00 GMT</pubDate><dc:creator>RyanRandall</dc:creator></item><item><title>RE: Simplify the Creation of XML from SQL Server Data</title><link>http://www.sqlservercentral.com/Forums/Topic221268-252-1.aspx</link><description>I'm still getting timeouts, is this a browser address?</description><pubDate>Fri, 28 Oct 2005 02:28:00 GMT</pubDate><dc:creator>hawryluk</dc:creator></item><item><title>RE: Simplify the Creation of XML from SQL Server Data</title><link>http://www.sqlservercentral.com/Forums/Topic221268-252-1.aspx</link><description>&lt;P&gt;Great, I got the attachments! Thanks.&lt;/P&gt;&lt;P&gt;This is a great solution to the problem. Many solutions include offloading the XML creation to SQL server, which just adds more stress to a single point of failure for most websites and applications. Also, it makes the SQL server output higher by adding XML tags and such at the SQL end. I dont like adding anything to SQL server I dont have to.&lt;/P&gt;&lt;P&gt;The one drawback (and it is a big one) is that you do not supply the source for the DLL. This is actually something which could be added to a good opensource project. If I dare use this DLL in a project for production, I have no guarantee that it will work in future versions of .net and if there is a bug in the library, I have no way to fix it myself or ask someone else to fix it. If this were open sourced or even made available for purchase from a company that would be around a while, that would be great and I would start using it immediately.&lt;/P&gt;&lt;P&gt;Paul Perrick&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description><pubDate>Fri, 28 Oct 2005 01:48:00 GMT</pubDate><dc:creator>Paul -244830</dc:creator></item><item><title>RE: Simplify the Creation of XML from SQL Server Data</title><link>http://www.sqlservercentral.com/Forums/Topic221268-252-1.aspx</link><description>What is this site? I get timeouts as well. &lt;img src='images/emotions/blink.gif' height='20' width='20' border='0' title='Blink' align='absmiddle'&gt;</description><pubDate>Fri, 28 Oct 2005 01:47:00 GMT</pubDate><dc:creator>hawryluk</dc:creator></item><item><title>RE: Simplify the Creation of XML from SQL Server Data</title><link>http://www.sqlservercentral.com/Forums/Topic221268-252-1.aspx</link><description>&lt;SPAN id=Showtread1_ThreadRepeater__ctl10_lblFullMessage&gt;I couldn't get it either ... &lt;/SPAN&gt;</description><pubDate>Thu, 27 Oct 2005 23:51:00 GMT</pubDate><dc:creator>Bert De Haes</dc:creator></item><item><title>RE: Simplify the Creation of XML from SQL Server Data</title><link>http://www.sqlservercentral.com/Forums/Topic221268-252-1.aspx</link><description>I couldn't get it either.</description><pubDate>Thu, 27 Oct 2005 23:30:00 GMT</pubDate><dc:creator>Undebtedly</dc:creator></item><item><title>RE: Simplify the Creation of XML from SQL Server Data</title><link>http://www.sqlservercentral.com/Forums/Topic221268-252-1.aspx</link><description>&lt;P&gt;Anyone had any success at getting to the tech.rssgroup.com website?&lt;/P&gt;&lt;P&gt;I've tried from my work computer and home computer and just get connection timeout errors. &lt;img src='images/emotions/sad.gif' height='20' width='20' border='0' title='Sad' align='absmiddle'&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description><pubDate>Thu, 27 Oct 2005 19:27:00 GMT</pubDate><dc:creator>philcart</dc:creator></item><item><title>RE: Simplify the Creation of XML from SQL Server Data</title><link>http://www.sqlservercentral.com/Forums/Topic221268-252-1.aspx</link><description>&lt;P&gt;please find the download at:&lt;/P&gt;&lt;P&gt;&lt;A href="http://tech.rssgroup.com/shapes/RSSWebShapes.zip"&gt;http://tech.rssgroup.com/shapes/RSSWebShapes.zip&lt;/A&gt;&lt;/P&gt;&lt;P&gt;and a sample site at&lt;/P&gt;&lt;P&gt;&lt;A href="http://tech.rssgroup.com/shapes"&gt;http://tech.rssgroup.com/shapes&lt;/A&gt;&lt;/P&gt;&lt;P&gt;thanks for the interest!  let me know if you have any installation troubles or further questions.&lt;/P&gt;&lt;P&gt;cheers,&lt;/P&gt;&lt;P&gt;Hugh&lt;/P&gt;</description><pubDate>Thu, 27 Oct 2005 08:05:00 GMT</pubDate><dc:creator>Hugh Lynch</dc:creator></item><item><title>RE: Simplify the Creation of XML from SQL Server Data</title><link>http://www.sqlservercentral.com/Forums/Topic221268-252-1.aspx</link><description>I to would like to test this code and wish there was a link to download the files.  I could use this I believe.</description><pubDate>Thu, 27 Oct 2005 06:52:00 GMT</pubDate><dc:creator>Todd Miller</dc:creator></item><item><title>RE: Simplify the Creation of XML from SQL Server Data</title><link>http://www.sqlservercentral.com/Forums/Topic221268-252-1.aspx</link><description>&lt;P&gt;After just resorting to VBScript to create an XML file, I too would love to see the download.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description><pubDate>Thu, 27 Oct 2005 06:26:00 GMT</pubDate><dc:creator>philcart</dc:creator></item><item><title>RE: Simplify the Creation of XML from SQL Server Data</title><link>http://www.sqlservercentral.com/Forums/Topic221268-252-1.aspx</link><description>&lt;P&gt;I agree - the article was great.  &lt;/P&gt;&lt;P&gt;One link does work: &lt;A href="http://tech.rssgroup.com/shapes/"&gt;http://tech.rssgroup.com/shapes/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Re: "&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;&lt;STRONG&gt;&lt;EM&gt;The accompanying download includes the binary and configuration files necessary to experiment with shapes on your own.&lt;/EM&gt;&lt;/STRONG&gt;"  &lt;/SPAN&gt;There's no download available with the article -- did you (or the folks at SQLServerCentral) forget to include it?&lt;/P&gt;&lt;P&gt;Regards, BobM&lt;/P&gt;</description><pubDate>Thu, 27 Oct 2005 06:22:00 GMT</pubDate><dc:creator>Bob Monahon</dc:creator></item><item><title>RE: Simplify the Creation of XML from SQL Server Data</title><link>http://www.sqlservercentral.com/Forums/Topic221268-252-1.aspx</link><description>&lt;P&gt;Loved the article, but none of the links work, and no download to try it.&lt;img src='images/emotions/satisfied.gif' height='20' width='20' border='0' title='Satisfied' align='absmiddle'&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Jason Hawryluk&lt;/P&gt;</description><pubDate>Thu, 27 Oct 2005 01:44:00 GMT</pubDate><dc:creator>hawryluk</dc:creator></item><item><title>RE: Simplify the Creation of XML from SQL Server Data</title><link>http://www.sqlservercentral.com/Forums/Topic221268-252-1.aspx</link><description>&lt;P&gt;Perfect timing on this article too. I am about to implement some AJAX code and was looking for the right solution for generating the XML output from SQL. &lt;/P&gt;&lt;P&gt;The article is well written except I could not find a download link for the samples and the link at the bottom of the article to a Shape testing server is &lt;A href="http://localhost/"&gt;http://localhost/&lt;/A&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Thanks for the article.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description><pubDate>Thu, 27 Oct 2005 01:30:00 GMT</pubDate><dc:creator>Paul -244830</dc:creator></item><item><title>RE: Simplify the Creation of XML from SQL Server Data</title><link>http://www.sqlservercentral.com/Forums/Topic221268-252-1.aspx</link><description>&lt;P&gt;Great article. &lt;/P&gt;&lt;P&gt;I would really like to see how this is implemented, but could not find the download ?&lt;/P&gt;</description><pubDate>Thu, 27 Oct 2005 01:00:00 GMT</pubDate><dc:creator>Bert De Haes</dc:creator></item><item><title>Simplify the Creation of XML from SQL Server Data</title><link>http://www.sqlservercentral.com/Forums/Topic221268-252-1.aspx</link><description>&lt;P&gt;Comments posted to this topic are about the content posted at &lt;A href="http://www.sqlservercentral.com/columnists/hlynch/simplifythecreationofxmlfromsqlserverdata.asp"&gt;http://www.sqlservercentral.com/columnists/hlynch/simplifythecreationofxmlfromsqlserverdata.asp&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Here is the download:&lt;/P&gt;&lt;P&gt;&lt;A href="http://tech.rssgroup.com/shapes/RSSWebShapes.zip"&gt;http://tech.rssgroup.com/shapes/RSSWebShapes.zip&lt;/A&gt;&lt;/P&gt;&lt;P&gt;and at&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.hughlynch.com/shapes/RSSWebShapes.zip"&gt;http://www.hughlynch.com/shapes/RSSWebShapes.zip&lt;/A&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description><pubDate>Mon, 19 Sep 2005 12:35:00 GMT</pubDate><dc:creator>Hugh Lynch</dc:creator></item></channel></rss>