posted by Jayson Knight on Mon 16th Feb 2004 19:05 UTC
IconWith the hype growing to a feverish pitch about the public announcement of Xen, I thought I would share some insight into the knowledge I've had of the language for almost a year and a half. I'm still under orders not to post the video demonstration I have back to my blog (not because the subject matter is Xen, but because apparently the demonstration is internal to Microsoft... I still don't understand this (expecially now that the cat is out of the bag), but it certainly doesn't stop me from sharing some of the information contained in it. This will be an ongoing post as the demonstration is over an hour long, with lots of code samples to boot.

Note: This article was submitted for publication by Jayson Knight, a certified Microsoft Solution Provider.

I won't rehash the whole "programming with rectangles, triangles, and circles" paradigm that seems to be the encompassing theme of Xen, simply do a search on any search engine for Xen/X# for that kind of information.

One of the first things mentioned is about declarative languages, XML and XSLT falling neatly into that category. one of the fallbacks of declarative languages is lack of typing/loose typing, and being late bound and uncompiled/interpreted. the ultimate end goal of Xen will be something that is 100% reliant on the CLR type system, and also fully compiled and optimized. while there are numerous primitives in XML/XSLT, extracting this data from the document at this point is done almost entirely using string types for all of these. this is something that simply must be overcome (v 2.0 makes some serious inroads into this, but nowhere near as much as Xen, as you'll see shortly). in the .Net world, there are basically 3 seperate type systems:

The SQL type system, encompassing TSQL and SQL types (varchar, money, etc)
The XSD type system, which provides Xml serialization functionality and encompasses XML, XPath, XSLT, and XQuery
The CLR type system, which includes all of the .Net types that i am sure everyone is quite familiar with
There are 3 sets of API's to bring these 3 type systems together:

ADO.NET for the CLR - SQL bridge
SQL XML for the SQL - XSD bridge
System.Xml for the XSD - CLR bridge
now for some code. here the way you would typically handle some data extraction from and XML document using the DOM:

decimal AddTotal(XmlDocument doc, int zip) {
decimal total = 0;
foreach (XmlElement item in 
  XmlElement price = item.SelectSingleNode("price");
  XmlElement qty = item.SelectSingleNode("quantity")
  decimal p = Decimal.Parse(price.InnerText);
  decimal q = Decimal.Parse(quantity.InnerText);
  total += p * q;
return total; 


This is most defintely a functional snippet, however it's string based typing with lots of casts, and overall isn't that readable, and notice the way the XPath query is assembled using an assortment of double and single quotes. of course, you can use the XmlSerializer class to work around some of the typing issues as such:

class Order {
    public Item[] Items;
class Item {
   [XmlAttribute] int id;
          public int Zip;
          public decimal Price;
          public decimal Quantity;

XmlSerializer s = new XmlSerializer(typeof(Order[])); 
Order[] orders = (Order[])s.Deserialize(stream);


decimal AddTotal(Order[] orders, int zip) {
decimal total = 0; 
foreach (Order o in orders) {
    if (o.Zip == zip) 
        foreach (Item item in o.Items) {
           total += item.Price * item.Quantity;
return total; 

Table of contents
  1. "Intro to Xen, Page 1/3"
  2. "Intro to Xen, Page 2/3"
  3. "Intro to Xen, Page 3/3"
e p (0)    35 Comment(s)

Technology White Papers

See More