And you thought XLinq was cool? 1

Posted by Jb Evain Mon, 01 May 2006 08:41:00 GMT

Today, I’m stuck to bed due to something that appears to be a Gastroenteritis. Don’t worry, I won’t give any detail, but wow, I’ve forgot I contain so much fluids.

Please notice that there is no relation between XLinq and Gastroenteritis.

I’ve read with pleasure this article about a new way to create xml files using ruby. And I’ve wonder how can I have the same thing on Mono. All I needed, was a language which supports duck typing. I have boo. I’m not a sitting duck Miles!

I took me a little more than an hour to have something working like the ruby library. I’ve translated the end of the article, which is about the creation of a xhtml document. Here is my boo version

import System

import NUnit.Framework

[TestFixture]
class XhtmlTestFixture:

    [Test]
    def go():
        x = XmlBuilder(Console.Out)

        x.Instruct_("xml",
            {"version" : "1.0", "encoding" : "utf-8"})

        x.Declare_("html", "-//W3C//DTD XHTML 1.0 Strict//EN",
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd")

        x.html() do:
            x.head() do:
                x.title("My Projects")
                x.style({"type" : "text/css"}) do:
                    x.Text_("body {font-family: courier new;}")

            x.body() do:
                x.h1("My projects")

                x.p("The projects I'm working on:")

                x.ul() do:
                    x.li("Mono")
                    x.li("Cecil")
                    x.li("...")

Here is the project of the whole thing, including unit tests.

Notice that it could of course be improved, especially, the XmlBuilder thing could extends XmlTextWriter. But this was simple enough for me. Cool huh?

Trackbacks

Use the following link to trackback from your own site:
http://evain.net/blog/articles/trackback/65

Comments

Leave a response

  1. Brandon Barry Mon, 01 May 2006 15:13:04 GMT

    Builder reminds me of py.xml and XIST (the inspiration for py.xml).

    I’ve only used py.xml (I can’t vouch for XIST), but you might be able to incorporate some of their ideas into your project.

    If being sick (hope you’re better soon) has left you with time to read, I highly recommend looking at py.test. After using it for a little while I’m hooked.

Comments