New XML macro idea

2 views
Skip to first unread message

Andrew Davey

unread,
Oct 18, 2009, 5:34:39 PM10/18/09
to Nemerle Forum
I had an idea this weekend for creating XML expressions in Nemerle.

def x = xml [html,
[head, [title, "Test"]],
[body,
[p, @class="main", "Hello, World", [br], "test"],
[ul, items.Map(i => xml [li, i])],
[p, [a, href="#", "click here"]]
]
];

A list literal is converted into something like XElement
("element_name", args...).
"name = value" expressions are converted into XAttribute("name",
value).
Other embeded expressions works are inserted as-is.

Not much code was required for the macro. I'll try to get it into a
blog post soon.

Ķaмĭļ ๏ Şκaļşκĭ

unread,
Oct 19, 2009, 3:14:11 PM10/19/09
to nemer...@googlegroups.com
On Sun, Oct 18, 2009 at 2:34 PM, Andrew Davey <a.j....@gmail.com> wrote:
>
> I had an idea this weekend for creating XML expressions in Nemerle.
>
>    def x = xml [html,
>        [head, [title, "Test"]],
>        [body,
>            [p, @class="main", "Hello, World", [br], "test"],
>            [ul, items.Map(i => xml [li, i])],
>            [p, [a, href="#", "click here"]]
>        ]
>    ];
>
> A list literal is converted into something like XElement
> ("element_name", args...).
> "name = value" expressions are converted into XAttribute("name",
> value).
> Other embeded expressions works are inserted as-is.
>

Yeah, that could work, but I'm not sure this is really an improvement
over any other encoding of xml literals... even strings.

BTW. are you really going to insert lots of xml literals inside your code?


> Not much code was required for the macro. I'll try to get it into a
> blog post soon.
> >
>



--
Kamil Skalski
http://kamil-skalski.pl

emp...@gmail.com

unread,
Oct 19, 2009, 3:48:54 PM10/19/09
to Nemerle Forum
It might be useful for a tempate/view engine may be.

On Oct 19, 10:14 pm, Ķaмĭļ ๏ Şκaļşκĭ <kamil.skal...@gmail.com> wrote:

Ķaмĭļ ๏ Şκaļşκĭ

unread,
Oct 19, 2009, 5:10:03 PM10/19/09
to nemer...@googlegroups.com
On Mon, Oct 19, 2009 at 12:48 PM, emp...@gmail.com <emp...@gmail.com> wrote:
>
> It might be useful for a tempate/view engine may be.

Yes, but then anything, which does not look exactly like XML isn't
going to be very readable / useful. Also, I guess you don't want to
write templating engine, which is trying to transform written html
into real .NET XML objects... this would most likely:
1) suck in performance
2) won't be very convenient, since every tiny mistake, which HTML
happily accepts would cause some horrible compile-time errors
(NullPointer or other horrible exception when compiler tries to
instantiate objects form incorrect xml code)

Andrew Davey

unread,
Oct 20, 2009, 4:14:42 AM10/20/09
to Nemerle Forum
That's exactly what I have in mind. I have a view engine for asp.net
mvc called Hasic (http://www.assembla.com/wiki/show/hasic) that uses
VB.NET's XML literals. I want to do something similar in Nemerle. But,
I don't fancy writing a full parser, so using list literals is quick
and easy!
> > Kamil Skalskihttp://kamil-skalski.pl- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages