Datasheet
Klein c01.tex V3 - 12/13/2007 1:48pm Page 5
Chapter 1: Project LINQ
XQuery, or Extensible Stylesheet Language Transformations (XSLT). For example, to read an XML
document using existing technology, you would need to do something like the following:
XmlTextReader rdr = new XmlTextReader("C:
\
Employees.Xml");
while (rdr.Read())
{
XmlNodeType nt = rdr.NodeType;
Switch (nt)
{
case XmlNodeType.Element:
break;
case XmlNodeType.Attribute:
break;
case XmlNodeType.Comment:
break;
case XmlNodeType.Whitespace:
break;
}
}
That’s a lot of code just to read an XML document (and it isn’t even complete). Writing XML isn’t any
less confusing, as illustrated here:
XmlTextWriter wrt = new XmlTextWriter("C:
\
Employees.Xml");
wrt.WriteStartDocument;
wrt.WriteComment("This is an example");
wrt.WriteStartElement("Employees");
wrt.WriteStartElement("Employee");
wrt.WriteStartElement("FirstName");
wrt.WriteString("Scott");
wrt.WriteEndElement();
wrt.WriteEndElement();
wrt.WriteEndElement();
Visually, you don’t know if this will work until you compile the project. Likewise, it is hard to see what
the resulting XML will look like.
XML is great and its use continues to grow; you can expect it to be around for a long time. Yet, truth be
told, XML is still hard to work with.
In dealing with these hurdles, Microsoft considered two paths. The first path would have required the
company to build specific XML or relational data features into each programming language and run-time.
That would be a major undertaking and an even bigger hassle to maintain. The second option was to add
more general-purpose query capabilities into the .NET Framework—in other words, a framework of
all-purpose querying facilities built into the .NET Framework that both C# and VB.NET could easily take
advantage of.
Luckily, Microsoft chose the later option, creating a unified query experience across objects, XML,
collections, and data. It accomplished that by taking query set operations, transforms, and constructs and
bringing them to the surface, making them high-level concepts within the .NET Framework (for example,
5