Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Access SQLXML Technology from .NET Apps : Page 4

The SQLXML Managed Classes enable developers to access SQLXML technology from .NET applications. This article describes some of these classes and how to use them.


advertisement
Apply XSL Transformations
Another cool feature of SQLXML is that you can apply XSL transformations on an XML result document. This feature is particularly useful for programming data-driven Web sites:
  1. Access your database through SQLXML and XML views.
  2. Retrieve XML documents as the result.
  3. Transform these documents into HTML Web sites.

Follow these three steps and youll create a data-driven Web site without any database programming!

You can also apply XSL transformations in .NET applications by using the SQLXML Managed Classes. The following listing shows you how to apply these transformations:



using System; using System.IO; using System.XML; using System.XML.Xsl; using System.XML.XPath; using Microsoft.Data.SqlXML; public class XslTransformSample { public static void Main() { String strConnectionString = Provider=SQLOLEDB;Server=(local); database=Northwind;user id=sa;pwd=; Stream stream; SqlXMLCommand cmd = new SqlXMLCommand(strConnectionString); cmd.CommandText = SELECT * FROM Customers FOR XML AUTO; cmd.RootTag = ROOT; stream = cmd.ExecuteStream(); // Apply the XSL-Transformation XMLTextReader reader = new XMLTextReader(stream); XPathDocument xpath = new XPathDocument(reader, XMLSpace.Preserve); XslTransform xslt = new XslTransform(); xslt.Load(Transform.xsl, null); XMLTextWriter writer = new XMLTextWriter(output.html, System.Text.Encoding.UTF8); xslt.Transform(xpath, null, writer); } }

The file Transform.xsl contains the following transformation code:

<?XML-version=1.0 encoding=UTF-8 ?> <xsl:stylesheet version=1.0 XMLns:xsl=http://www.w3.org/1999/XSL/Transform> <xsl:output method=html /> <xsl:template match=*> <xsl:apply-templates /> </xsl:template> <xsl:template match=Customers> <tr> <td><xsl:value-of select= @CompanyName /><td> <td><xsl:value-of select= @ContactName /><td> </tr> </xsl:template> <xsl:template match=/> <html> <head> </head> <body> <table border=1> <tr> <td>Company Name</td> <td>Contact Name</td> </tr> <xsl:apply templates select=RootElement /> </table> </body> </html> </xsl:template>

Retrieve Data from Relational Databases
The basic idea behind SQLXML is enabling developers to retrieve data from relational databases like SQL Server through XML views. This technology also can be accessed in .NET applications through the SQLXML Managed Classes, which fit into the ADO.NET concept as well as the idea of dataset objects.



Klaus Aschenbrenner is CEO of the software company Solvion, which specializes in designing and programming enterprise applications based on the .NET Framework and Windows.NET. He has written articles for German magazines like DotNetPro and is a speaker at conferences. You can reach Klaus at Klaus.Aschenbrenner@csharp.at.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap