diff --git a/modules/goessner/json2xml.js b/modules/goessner/json2xml.js index acca15cc..5988c4df 100644 --- a/modules/goessner/json2xml.js +++ b/modules/goessner/json2xml.js @@ -30,9 +30,9 @@ var json2xml = (typeof exports === 'undefined')? {} : exports; // like commonjs if (hasChild) { for (var m in v) { if (m == "#text") - xml += v[m]; + xml += lines(v[m]); else if (m == "#cdata") - xml += ""; + xml += ""; else if (m.charAt(0) != "@") xml += toXml(v[m], m, ind+"\t"); } @@ -40,7 +40,7 @@ var json2xml = (typeof exports === 'undefined')? {} : exports; // like commonjs } } else { // added special-character transform, but this needs to be better handled [micmath] - xml += ind + "<" + name + ">" + v.toString().replace(/\n"; + xml += ind + "<" + name + ">" + makeSafe(lines(v.toString())) + "\n"; } return xml; }, @@ -52,5 +52,19 @@ var json2xml = (typeof exports === 'undefined')? {} : exports; // like commonjs return xml; } + + function lines(str) { + // normalise line endings, all in file will be unixy + str = str.replace(/\r\n/g, '\n'); + + return str; + } + + function makeSafe(str) { + // xml special charaters + str = str.replace(/