[ANN] Javascript Builder for XML

2 views
Skip to first unread message

s.ross

unread,
Apr 4, 2009, 1:02:36 AM4/4/09
to jazzr...@googlegroups.com
I've been using Jazzrecord in an AIR app, and got pretty frustrated
cobbling together all the HTML I was inserting into the DOM. The
result: A small chunk of Javascript you can yank into your codebase so
you can use a Builder pattern to created markup. Find it on GitHub:

http://github.com/sxross/js_xmlmarkup/tree/master

There are some examples in the README, but for a taste, say you are
populating a table from your database:

xml = new XmlMarkup();
xml.tag('table', function() {
xml.tag('thead', function() {
xml.tag('tr', function() {
xml.tag('th', 'common name');
xml.tag('th', 'species');
xml.tag('th', 'genus');
xml.tag('th', 'family');
})
});

// This part is the interesting part from
// the perspective of using an ORM -- you
// just keep writing Javascript. No slipping
// into HTML and popping back out. Control
// structures and markup instructions in the
// same language, oh my!
xml.tag('tbody', function() {
for(animal in Animal.all()) {
xml.tag('tr', function() {
xml.tag('td', animal.common_name);
xml.tag('td', animal.species);
xml.tag('td', animal.genus);
xml.tag('td', animal.family);
})
}
});
});

jQuery('#animal-family').html(xml.target());

This is only in use in my code at present, so it's very early stuff. I
have one optimization planned that should help with large recordsets.
It's simple and brutally obvious -- I just haven't gotten around to it
yet. I will be changing the string concatenation into array assembly
to reduce the string allocation and discarding.

Steve

Reply all
Reply to author
Forward
0 new messages