The following samples are written entirely in the Xen Programming Language and demonstrate the various aspects of the Xen Type System and what is possible with the XML and SQL integration in Xen.
Some of these samples connect to the Northwind database released with SQL 2000. These samples store the database connection string in the application configuration file named *.exe.config. Before running these samples you may need to modify those settings to point to a SQL server database that you have access to.
Xen PetShop and NorthwindASP samples require IIS and ASP.Net installed on your machine. If you had IIS installed on your machine at the time you installed Xen, installer has already configured it for you and you are all set to proceed to samples.
In case you did not have IIS installed, in order to run Xen PetShop or NorthWind ASP samples, please perform the following steps:
This sample is based on .Net Pet Shop Case Study (1.3). The data access part of the sample is rewritten using Xen SQL features: select, insert, update, and delete expressions and transaction blocks. See for details source file XenPetShop\Components\SqlStoredProc.xs
Here are some of the highlights from the comparison between the original sample and its Xen version:
- No more SQL statement in quoted strings. Instead SQL select, insert, update and delete statements are part of the language syntax.
- No more runtime errors for possible illegal SQL syntax. Instead SQL syntax is verified at compiler time.
- No more runtime errors for possible database schema mismatch. Instead database schema is imported as managed types and is verified at compiler time.
- No more messing with SqlParameters. Instead you simply pass local variable into a select expression.
- No more IDataReader and manual copying of data into your managed structures. Instead built-in tuple type is used or custom objects can be constructed directly in the select statement.
- No more transaction API. Instead a built-in transaction block is used and it ensures no missing commit or rollback.
Before running Xen PetShop Sample you will need to install the PetShop DataBase. Make sure you have SQL 2000 server and a user name/password that has sufficient permissions to create a database. Perform the following steps:
- Modify installation script XenPetShop\DataBase\CreateDatabase.cmd supplying a server name, login name and password as instructed in the file.
- Execute the installation script XenPetShop\DataBase\CreateDatabase.cmd on the machine that has SQL 2000 Client tools installed. The script will install the Petshop data base prepopulate necessary data. The script will also create a user xenpetshop with password xenpetshop
- Open XenPetshop\XenPetshop.xsproj project, file web.config and modify in the appSettings section the name of the server (by default 'xenhost') to point to the server that you just configured.
To run the sample, compile XenPetshop\XenPetshop.xsproj and launch the default.aspx page.
This is an ASP.NET application that connects to SQL Server Northwind database via an tool-generated "interop" assembly named Northwind.dll and produces an HTML table showing lists of customers and orders. This is done via a custom System.Web.Control implemented in Xen that does the SQL select and yields XML literals that build the HTML tables using a simple set of HTML objects that are modeled in Xen. The HTML is generated as XML, so it is really XHTML. This XML output could be any user defined XML and is not limited to HTML. Check out main.xs where you will see very tight integration between the SQL queries on one side and the XHTML generation on the other, especially in the OrderDetails class.
To run this sample, load NorthwindASP.xsproj in Visual Studio, check the Web.Config file to make sure the Northwind database connection string is correct, build the project and launch the web page CustomersByCountry.aspx.
This sample is based on the W3C XQuery Use Cases . It demostrates the power of the Xen type system and object queries capabilities, and demonstrates the impact of adding strong typing to an XML query language. To run this sample, load the xquery.xsproj project in Visual Studio and hit F5. This sample includes a readme that discusses the differences between XQuery and Xen in these various use cases.
This is a WinForms demo that loads customer information out of the Northwind database and presents it in a grid. It also caches the customer information locally in a cache.xml file using the XmlSerializer. This demo shows a consistent programming model over XML and SQL data. It also shows how objects can be constructed directly in the SQL select projection list using XML literal expressions. To run this sample, check the sqlxml.exe.config file to make sure the Northwind database connection string is correct, then load the sqlxml.xsproj project in Visual Studio and hit F5.
This is a WinForms demo showing Xen XML literal expressions for manipulating SVG graphic elements. SVG is the W3C XML standard for Scalable Vector Graphics. Included with this sample is a separate svg.dll which renders SVG graphics and the interface between this dll and the Xen sample is a serialized stream of XML data. So this sample also shows how to use the Xen XmlSerializer which has extended serialization capabilities based on the Xen type system extensions. To run this sample, load the demo.xsproj project in Visual Studio and hit F5.
This demo shows the Xen equivalent of the Ledger.xsl style sheet. The demo loads XML data via XmlSerialization and transforms it to XHTML objects using a nested series of transforming "iterators" then it displays the result in a Web Browser control. This shows than Xen can do some XSLT scenarios just as elegantly as XSLT, but because Xen is based on a general purpose programming language the Xen approach is also more powerful. For example, the XSL style sheet requires the use of <msxsl:script> blocks for some things. In Xen this code is inlined, which makes it more managable and a lot more debuggable. To run this sample, load the Ledger.xsproj project in Visual Studio and hit F5.
WARNING: You may get an error during compilation about missing Microsoft.mshtml.dll. In this case close VS, open ledger.xsproj in the notepad and change the HintPath attribute value on the
element for the Microsoft.mshtml assembly to point to \Program Files\Microsoft.NET\Primary Interop Assemblies\Microsoft.mshtml.dll
The Shakespeare XML samples by Jon Bosak are an XML industry classic. In this sample we took the Play.dtd, converted it to XSD, then imported the XSD into a Xen project. This shows how to use the XmlSerializer to round trip the Hamlet.xml document which demonstrates good fidelity between XML content models and the Xen type system.