Tuesday, 11 May 2010

XmlPrime 1.4.0 Released

The release of XmlPrime 1.4.0 has arrived.

The biggest new feature in this version is the ability to write modules as classes in .NET, and call them from XQuery or XPath. Here is an example of a module written in C#

[XdmModule("http://www.mymodule.com/")]
public class MyModule
{
[XdmFunction("green-bottles")
public static XPathAtomicValue GreenBottles(XPathAtomicValue count)
{
var builder = new StringBuilder();
for (var x=count.ValueAsDecimal; x>0; x--)
{
builder.Append(x);
builder.Append(" green ");
builder.Append(x == 1 ? "bottle" : "bottles");
builder.Append(" sitting on the wall\n")

builder.Append(x);
builder.Append(" green ");
builder.Append(x == 1 ? "bottle" : "bottles");
builder.Append(" sitting on the wall\n")

builder.Append("And if one green bottle should accidently fall\n")

builder.Append("There'll be ");
builder.Append(x == 1 ? "no" : x - 1);
builder.Append(" green ");
builder.Append(x == 2 ? "bottle" : "bottles");
builder.Append(" sitting on the wall\n")

if (x != 1)
builder.Append("\n");
}

return XPathAtomicValue.Create(builder.ToString());
}
}

Which can now be called from XQuery as so:

import module namespace my="http://www.mymodule.com/";

<lyrics>{my:green-bottles(10)}</lyrics>

More detailed information about the improved modules support can be found here.

There have also been a number of performance improvements, in particular to join analysis.

For the full list of new features see the change log.

As usual, you can download your free copy now (for trial or non-commercial use).

No comments:

Post a Comment