Last active
March 23, 2016 09:11
-
-
Save s-melnikov/e453aadda8c102631420 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| function xml(params) { | |
| var doc; | |
| function node(parent, params) { | |
| if (!doc) { | |
| doc = document.implementation.createDocument("", params.name, null); | |
| el = doc.documentElement; | |
| } else { | |
| var el = doc.createElement(params.name); | |
| parent.appendChild(el); | |
| } | |
| for (var prop in (params.attrs || {})) { | |
| el.setAttribute(prop, params.attrs[prop]); | |
| } | |
| for (var i = 0, ln = (params.childs || []).length; i < ln; i++) { | |
| node(el, params.childs[i]); | |
| } | |
| !params.childs && params.text && el.appendChild(doc.createTextNode(params.text)); | |
| } | |
| node(null, params); | |
| return doc; | |
| } | |
| var xml = xml({ | |
| name: "server", | |
| attrs: { forsearch: "999-999-999", command: "bet", status: "bong" }, | |
| childs: [ | |
| { name: "playinfo", attrs: { minutes: "772", win: "33.800000" }} | |
| ] | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment