This repository was archived by the owner on Jan 7, 2021. It is now read-only.

Description
Expected Behavior
toXml method should be able to reverse the JSON with different keys in the text nodes
Current Behavior
When using the toJson method with the reversible and ʻalternateTextNode` option set to true, the response returned by the method is not reversible with the toXml method.
Possible Solution
add the alternateTextNodes option in the ToXml class and use this option to evaluate if the element is a text node
Steps to Reproduce
- Parse a valid xml with the
toJson method, the method must have the reversible and alternateTextNode options.
- The returned object must be passed to the
toXml method.
Possible Implementation
File lib/json2xml.js ToXml class
function ToXml(options) {
var defaultOpts = {
sanitize: false,
ignoreNull: false,
alternateTextNode: false,
};
if (options) {
for (var opt in options) {
defaultOpts[opt] = options[opt];
}
}
this.options = defaultOpts;
this.xml = '';
this.tagIncomplete = false;
if(typeof this.options.alternateTextNode === "boolean" ) {
thist.textNodeKey = this.options.alternateTextNode ? "_t" : "$t";
} else if (typeof this.options.alternateTextNode === "string") {
this.textNodeKey = this.options.alternateTextNode;
} else {
// or set by default "$t"
throw new Error("Expected string or boolean value for the alternateTextNode option");
}
}
File lib/json2xml.js line 39
if (key == this.textNodeKey) {
self.addTextContent(subVal);
} else {
self.addAttr(key, subVal);
}