Toggle navigation
P3X GitList Snapshot
GitHub
Repo
Changelog
To do
Releases
Themes
Change log
Loading change log ...
To do ...
Loading todo ...
browsing:
6bef41462bdf11762df4d9a96f04fb03e251b1f5
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: 12
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;
db251bde
// First pass, extract strings only for (var i = 0; i < len; i++) {
29b9b183
var key = keys[i], value = obj[key], isArray = Array.isArray(value);
69a937d4
var type = typeof(value); if (type == 'string' || type == 'number' || type == 'boolean' || isArray) {
29b9b183
var it = isArray ? value : [value]; it.forEach(function(subVal) { if (typeof(subVal) != 'object') { if (key == '$t') { xml += subVal; } else { xml = xml.replace(/>$/, ''); xml += ' ' + key + '="' + subVal + '">'; } } })
db251bde
} } // Second path, now handle sub-objects and arrays
8407d456
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++) {
29b9b183
var elem = elems[j]; if (typeof(elem) == 'object') { xml += '<' + key + '>'; xml = toXml(elem, xml); xml += '</' + key + '>'; }
8407d456
} } else if (typeof(obj[key]) == 'object') { xml += '<' + key + '>';
3b173cb4
xml = toXml(obj[key], xml);
8407d456
xml += '</' + key + '>'; } } return xml; };