Michael Rys

Musings on XML, XQuery and more...

<August 2008>
SuMoTuWeThFrSa
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456


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



CLR UDF Example: TransformXML.cs

/*=====================================================================

  File:      TransformXML.cs
  Summary:   A CLR UDF to transform XML using an XSLT
  Date:      Apr 5, 2005

---------------------------------------------------------------------

  Copyright (C) Microsoft Corporation.  All rights reserved.

This source code is intended only as a supplement to a Microsoft
WebCast.

THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

======================================================= */

using System;
using System.Data.SqlTypes;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;

 /// <summary>
 /// Implements CLR UDF to transform an XML datatype instance with XSLT stylesheet
 /// (provided with local file path).
 /// </summary>
 public class TransformXml
 {

  public static SqlXml ApplyXslTransform (
    SqlXml XmlData,
    string xslPath)
  {
   // Load XSL transformation
   XslCompiledTransform xform = new XslCompiledTransform();
   xform.Load (xslPath);

   // Execute/Cache results
   XmlDocument resultsDoc = new XmlDocument();
   XPathNavigator resultsNav = resultsDoc.CreateNavigator();
   // using makes sure that we flush the writer at the end
   using (XmlWriter writer = resultsNav.AppendChild())
   {
    xform.Transform(XmlData.CreateReader(), writer);
   }

   // Return results
   SqlXml retSqlXml = new SqlXml (resultsNav.ReadSubtree());
   return (retSqlXml);
  }

 }

posted on Tuesday, April 12, 2005 12:36 PM by mrys


# Material for my MSDN WebCast &amp;quot;Managing XML Data on the Database with SQL Server 2005 and Visual Studio 2005&amp;quot; @ Tuesday, April 12, 2005 4:43 PM

You can get the WebCast recording and copies of the slides&nbsp;from the MSDN website (registration required)....

mrys

# The SQL Server XML weblogs are blooming and other &amp;amp;amp;quot;news&amp;amp;amp;quot; @ Wednesday, July 13, 2005 2:15 AM

While I have been a bit quiet over the last couple of weeks mainly due to presenting at two TechEd's,...

Anonymous

# The SQL Server XML weblogs are blooming and other &amp;amp;quot;news&amp;amp;quot; @ Wednesday, July 13, 2005 3:03 AM

While I have been a bit quiet over the last couple of weeks mainly due to presenting at two TechEd's,...

Anonymous




Powered by Dot Net Junkies, by Telligent Systems