Toggle navigation
P3X GitList Snapshot
GitHub
Repo
Changelog
To do
Releases
Themes
Change log
Loading change log ...
To do ...
Loading todo ...
browsing:
e4c71b31f0c81b1223a8e38fe982fffa0b685078
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: 16
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) {
e4c71b31
var it = isArray ? value : [value];
29b9b183
e4c71b31
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++) {
e4c71b31
var elem = elems[j];
29b9b183
e4c71b31
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; };