July 28, 2005

Erik Saltwell: "What the heck is OutputSettings"

Erik Saltwell explains what this XslCompiledTransform.OutputSettings property is and why it exists. That's really fresh, clean and powerful design once you get it. I didn't first. ...

July 26, 2005

XML and .Net: fascinating future

If you thought that some smell of XML in C-omega was amazing, believe me that's nothing. Major XML and .NET integration stories are still ahead of us. Something big is cooking inside the house. Look at these news. ...

From the PDC 2005 Session abstracts:

The .NET Language Integrated Query Framework: An Overview
Modern applications operate on data in several different forms: Relational tables, XML documents, and in-memory objects. Each of these domains can have profound differences in semantics, data types, and capabilities, and much of the complexity in today's applications is the result of these mismatches. The "Orcas" release of Visual Studio aims to unify the programming models through integrated query capabilities in C# and Visual Basic, a strongly typed data access framework, and an innovative API for manipulating and querying XML. This session introduces each of these areas and walks through how they are related.
And more:
Using the .NET Language Integrated Query Framework with XML Data
One of the key challenges to working with XML data has been the impedance mismatch between XML and programming languages. This session introduces advances Microsoft is making for the "Orcas" release of Visual Studio in programming languages and frameworks to help integrate XML and queries with C# and Visual Basic. The advances include a framework for navigating, querying, and transforming XML that is both easier to use and more efficient than current XML programming techniques. This framework marries the capabilities of XPath, XQuery, and the DOM with the language integrated query framework planned for C# and Visual Basic.
Hmmm, marrying XPath, XQuery and DOM. That must be hot.

Actually that IQF (Integrated Query Framework) idea is really predictable and unavoidable. When you take a deep look at XPath, XSLT and XQuery as implementor you see how similar they are and naturally Microsoft came up with Query Intermediate Language (QIL) Common Query Runtime (CQR). This stuff is not out of blue research project, it's already implemented in .NET 2.0! Ok, the only query language officially supported via this new common query machinery in .NET 2.0 is old good XSLT 1.0 - XslCompiledTransform class (but as you can guess of course XPath 1.0 is there too). But the architecture is ready for any XML query language, and just as with .NET all it takes to add support for a new language is to develop a compiler to QIL (analog of MSIL).

And if you take a broader view, the very next natural step is the Integrated Query Framework.

And if that's not enough, look at "XML Generics" by Matt Warren. That's really insane.

July 21, 2005

Mvp.Xml v1.1 released. Now including EXSLT.NET module

I've just finished moving EXSLT.NET code into the Mvp.Xml project infrastructure. Now on EXSLT.NET is a module of the Mvp.Xml library, its namespace is Mvp.Xml.Exslt, its license is CPL and its home page is http://mvp-xml.sourceforge.net/exslt. That's pretty much all changes. Go download Mvp.Xml library v1.1, now including EXSLT.NET module in ...

July 19, 2005

XPathReader v1.1 released

XPathReader v1.1 is available for download. XPathReader is originally developed inside Microsoft and then dropped out as open-source implementation of a pull-based XML parser that supports XPath queries while parsing the XML document. It's basically XmlReader that supports streaming subset of XPath 1.0. Read "The Best of Both Worlds: Combining ...

New in .NET 2.0: XPathNavigator finally has SelectSingleNode() method

In .NET 2.0 XPathNavigator finally has SelectSingleNode() method! MSXML and XmlDocument (XmlNode actually) have it forever and it's so widely used because it's soooo handy. Obviously despite its name, XPathNavigator.SelectSingleNode() returns not a node, but node equivalent in XPathNavigator's data model - XPathNavigator. And this method is even better than ...

July 18, 2005

nxslt 1.6 and nxslt2 Beta1 released

nxslt 1.6 and nxslt2 Beta1 are available for download. For those not familiar with nxslt: nxslt is free feature-rich .NET XSLT Command Line Utility. nxslt 1.6 is the next version for the .NET 1.X Frameworks. New features include optionality for source XML or stylesheet, pretty printing, ASCII only escaped output ...

July 17, 2005

New management, new project

The company I'm working latest 5 years for, Multiconn Technolgies, has melted finally down. 4 developers left including myself have been picked up by a parent company, BluePhoenix Solutions and so now on I'm working for a company with funny name Outlook & BluePhoenix. I will be woking on a ...

Tkachenko Family Blogroll

42. "Make all your family blogging" - done. Oleg (myself) - "Signs on the Sand" Alenka (my wife) - "Tigra Julia's Journal" (Russian only) Catherine (our little dauther) - "Little Catherine's Journal" (Russian only) Alexandra (my mom) - "wildgrass" (Russian only) ...

July 14, 2005

Microsoft Certification: MCP Program Takes New Road in September

Microsoft refreshes their professional certifications program: Changes are afoot in the Microsoft Certification Program that can be labeled as "evolutionary"; that is, changes to the certification process will be implemented over time, as newer technologies become generally available. According to Valvano, Microsoft will follow tradition, releasing exams for SQL Server ...

Expert Panel Podcast: SQL/XML, XQuery and Databases

Ken North: WebServicesSummit.com has released two podcasts of a panel discussion with Ron Bourret, Dana Florescu, Michael Kay, Jonathan Robie and Michael Rys. The discussion topics include XQuery, native XML databases, SQL/XML databases, XSLT and related topics. The part 1 podcast (MP3 audio) focuses primarily on XQuery (running time: 34:03 ...

July 12, 2005

Outputting HTML with XslCompiledTransform and XmlResolver

I was wrong in my last post. Here is how one can output HTML with XslCompiledTransform when XmlResolver needs to be passed to Transform() method. using (XmlReader src = XmlReader.Create("../../source.xml")) { XslCompiledTransform xslt = new XslCompiledTransform(); xslt.Load("../../style.xslt"); XmlWriter result = XmlWriter.Create(Console.Out, xslt.OutputSettings); xslt.Transform(src, null, result, new XmlUrlResolver()); } The key ...

So my the only left complaint about XslCompiledTransform's API is the lack of Transform(IXpathNavigable, XsltArgList, XmlWriter, XmlResolver) method. That means that if by any bad chance you happen to be transforming already loaded XmlDocument or XPathDocument and need to provide XmlResolver - you can't. You will need to pass XmlReader over your XmlDocument or XPathDocument (using XPathNavigator.ReadSubTree() method) and then XslCompiledTransform will load passed XmlReader into another XPathDocument! So your source XML in memory will be duplicated with no reason.

July 11, 2005

XslCompiledTransform API bug (update - not a bug, my fault)

I'm porting nxslt utility to .NET 2.0 with XslCompiledTransform as XSLT processor and I just found out XslCompiledTransform API is really severe broken. I was writing before that the only Transform() method overload that accepts XmlResolver outputs to XmlWriter. So if you want to create HTML and to have some ...

As Anton Lapounov pointed out XmlWriter is .NET 2.0 is actually capable to write not only XML, but also HTML or text. This behavior is controlled by XmlWriterSettings.OutputMethod property. But this property appears to be read-only (setter is internal). And after all this doesn't really solve my problem with nxslt utility porting, because in a general purpose XSLT utility XSLT output method should be controlled by a XSLT stylesheet, not by code that run transformation.

Update: I was wrong here. It can be done just fine with no any hacks, I just didn't get the way it's meant to be done. See more at the next post.

July 10, 2005

Loading XPathDocument with XmlWriter

What I dislike in System.Xml v2.0 (and v1.X for that matter) is a poor support for push-based XML processing. Somehow it's all about pull - XmlReader, while push - XmlWriter seems to be a second class citizen. For instance one can't populate XML into XPathDocument or XSLT stylesheet into XslCompiledTransform ...

As a matter of fact, XSLT chaining problem can be solved using XmlDocument, but alas it's still huge, slow and overkill for scenarios where read-only XML store is required.

Apparently this unfortunate state of the art has something to do with SAX vs XmlReader battles in early .NET days, which XmlReader definitely won. In .NET 1.X there wasn't even a standard way to write to XmlDocument using XmlWriter! Happily Chris Lovett came to the rescue with XmlNodeWriter.

An ultimate solution for the XML pipelining problem in .NET would be XmlWriterReader - a component that bridges XmlWriter and XmlReader. It can be implemented either by efficiently caching internally the whole stream of XmlWriter events and reading them after or by two-threaded synchronized XmlWriter/XmlReader. The good news is that it can be said for sure that soon such component will be implemented for the Mvp.Xml library. Stay tuned.

Still I wonder why all these hurdles. Let's take XPathDocument class. XSLT chaining problem could be solved be XPathDocument loadable from a XmlWriter. It's not. It accepts URI, Stream, TextWriter or XmlReader. But if you look inside XPathDocument you can see that it's constructed using XPathDocumentBuilder class, which implements XmlWriter! Put it another way: XPathDocument internally is constructed using only XmlWriter, but somehow it's impossible to populate it with your own XmlWriter. Weird, huh?

To prove it here is a little hackery showing it's feasible to populate XPathDocument with XmlWriter (it's a rude hack, don't use it):

//Create XPathDocumentBuilder
Type xpathDocBuilderType = 
  typeof(XPathDocument).Assembly.GetType(
    "MS.Internal.Xml.Cache.XPathDocumentBuilder");
XPathDocument doc = 
  (XPathDocument)Activator.CreateInstance(
    typeof(XPathDocument), 
    BindingFlags.NonPublic | BindingFlags.Instance, 
    null, new object[] { }, null);
ConstructorInfo xpathDocBuilderCtor = 
  xpathDocBuilderType.GetConstructors()[0];
XmlWriter xpathDocBuilder = 
  (XmlWriter)xpathDocBuilderCtor.Invoke(
  new object[] { doc, null, "", null });

//Populate XPathDocument
xpathDocBuilder.WriteStartElement("foo");
xpathDocBuilder.WriteAttributeString("attr", "value");
xpathDocBuilder.WriteString("content");
xpathDocBuilder.WriteEndElement();

//Done
Console.WriteLine(doc.CreateNavigator().OuterXml);
The output is
<foo attr="value">content</foo>

I wonder why this useful functionality isn't exposed. Apparently the reason is the added complexity. That would require to expose XPathDocumentBuilder and probably move to Builder pattern of constructing XPathDocument altogether. Ok, I've opened a suggestion at the MSDN Feedback Center, let's see what Microsofties say.

July 6, 2005

XSLT Puzzle from Dimitre Novatchev

I know I'm late, but anyway here is the latest Dimitre's puzzle. Don't post your anwers here, just send them him to dnovatchev AT gmail DOT com. Dimitre will be collecting answers only for another week, so hurry up. I just started reading the book "The Da Vinci code" and ...

July 5, 2005

Cool Web hosting news

Hey, I just noticed that Webhost4Life (web hosting company where I host my sites) greatly increased disk and database space available with their hosting plans - now for the same $10/mo one can get 2Gb of disk space, 2Gb of MS SQL and 2 Gb of MySQL. Hmm, 6 times ...