Toggle navigation
P3X GitList Snapshot
GitHub
Repo
Changelog
To do
Releases
Themes
Change log
Loading change log ...
To do ...
Loading todo ...
browsing:
8d5a5ca28fd3c338edee760f772071df3d4defb5
Branches
0.1
0.2
html-sanitizer
html-sanitizer-and-mocha-specs
master
sanitize-oversight
Tags
v0.11.2
v0.11.0
v0.9.2
v0.9.0
v0.8.2
v0.6.2
v0.6.1
v0.6.0
v0.5.1
v0.5.0
v0.4.0
v0.3.2
v0.3.1
v0.3.0
0.2.4
0.2.3
0.2.2
0.2.1
0.2.0
0.1.1
0.1.0
Files
Commits
Log
Graph
Stats
xml2json.git
lib
json2xml.js
RSS
Git
Fetch origin
Download
ZIP
TAR
Clone
Raw
View
History
Clone
SSH
HTTPS
Blames found: 6
Mode: javascript
Binary: false
Hang on, we reloading big blames...
3b173cb4
module.exports = function toXml(json, xml) { var xml = xml || '';
8407d456
if (json instanceof Buffer) { json = json.toString(); } var obj = null; if (typeof(json) == 'string') { try { obj = JSON.parse(json); } catch(e) { throw new Error("The JSON structure is invalid"); } } else { obj = json; } var keys = Object.keys(obj); var len = keys.length; for (var i = 0; i < len; i++) { var key = keys[i]; if (Array.isArray(obj[key])) { var elems = obj[key]; var l = elems.length; for (var j = 0; j < l; j++) { xml += '<' + key + '>';
3b173cb4
xml = toXml(elems[j], xml);
8407d456
xml += '</' + key + '>'; } } else if (typeof(obj[key]) == 'object') { xml += '<' + key + '>';
3b173cb4
xml = toXml(obj[key], xml);
8407d456
xml += '</' + key + '>'; } else if (typeof(obj[key]) == 'string') { if (key == '$t') { xml += obj[key]; } else { xml = xml.replace(/>$/, ''); xml += ' ' + key + "='" + obj[key] + "'>"; } } } return xml; };