Created
November 3, 2009 23:01
-
-
Save aconbere/225553 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
build = 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 = build(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; | |
}; | |
/* | |
var iq = xml('iq', {xmlns: "http:..."}, function() { | |
this.xml('query', {xmlns: 'http://jabber.org/protocol/disco#items', node: "root"}, function() { | |
for(var i = 0; i < 10; i++){ | |
this.xml('item', {}, function() { | |
this.text('item-' + i); | |
}); | |
} | |
}); | |
}); | |
output | |
<iq xmlns="http:..."> | |
<query xmlns="http://jabber.org/protocol/disco#items" node="root"> | |
<item>item+1</item> | |
<item>item+2</item> | |
<item>item+9</item> | |
</query> | |
</iq> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment