July 01, 2006

BooML – Language Integrated XML in Boo

Creating XML using the .NET XmlWriter object model tends to make your code look awful. I realised that using some mackery I could make Boo support creating XML right in the language. Thus was born "BooML"

Here is a little example.

import System
import System.IO
import System.Xml
import BooML

class Book:
private _title as string
private _author as string

def GetBooks():
return [
Book(Title: "Foo Bar", Author: "Bob Smith"),
Book(Title: "Test Title", Author: "Andrew Davey")

def GetBooksXml(books):
for book as Book in books:
@id = book.GetHashCode()
title book.Title
author book.Author

xml = GetBooksXml(GetBooks())
print xml.ToString()
The resulting XML is:
<?xml version="1.0" encoding="utf-8"?>
<book id="54267293">
<title>Foo Bar</title>
<author>Bob Smith</author>
<book id="18643596">
<title>Test Title</title>
<author>Andrew Davey</author>

The magic is in the XmlLiteral AST Attribute. It transforms macros (in the example: books, book, @id, title and author) into XML macros. The XML macros then in turn create the XmlTextWriter calls.

I think this could be a really powerful language enhancement for people doing web development who want to return abitrary XML from methods.

I may start a SourceForge project to open source the development.

- No comments Not publicly viewable

Add a comment

You are not allowed to comment on this entry as it has restricted commenting permissions.

Google Ads

Search this blog

Most recent comments

  • I scratched my eye while i was holding some kind of plastic packaging.. Anyways the corner of the pl… by Ercan on this entry
  • About a year ago my contacts that i was wearing, i guess were fautly, because shortly after they wer… by Jon on this entry
  • I got shower gel in my eye 4 and a half days ago, and becasue i rubbed my eyes a lot, i have scratch… by Chris on this entry
  • This website may help http://www.webmd.com/eye–health/tc/Eye–Injuries–Home–Treatment by S on this entry
  • I somehow got dirt, or debris in my eye. The terrible pain sent me in a tailspin. I was afraid of sa… by Bobbi on this entry


July 2006

Mo Tu We Th Fr Sa Su
Jun |  Today  | Aug
               1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30


Blog archive

Not signed in
Sign in

Powered by BlogBuilder