Skip to content

Instantly share code, notes, and snippets.

@julien51
Forked from aconbere/gist:225522
Created November 3, 2009 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julien51/225525 to your computer and use it in GitHub Desktop.
Save julien51/225525 to your computer and use it in GitHub Desktop.
buildNode = function(tag, attrs){
var node = document.createElement(tag);
for(var k in attrs) {
node.setAttribute(k, attrs[k])
}
return node;
};
text = function(text) {
return document.createTextNode(text);
};
xml = function(tag, attrs, closure){
var node = buildNode(tag, attrs);
if(closure) {
var scope = {
xml: function(tag, attrs, closure) { node.appendChild(xml(tag, attrs, closure));},
text: function(t) { node.appendChild(text(t)); }
};
closure.apply(scope);
}
return node;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment