xml-js
xml-js copied to clipboard
Doesn’t handle invalid characters
Run the following program:
const xmlJs = require("xml-js");
const fs = require("fs");
fs.writeFileSync(
"example.xml",
xmlJs.js2xml(
{
example: {
_text: "A control character (backspace): \b"
}
},
{ compact: true }
)
);
According to https://www.xmlvalidation.com, the produced example.xml is invalid. xml-js could provide an option to clean these characters (see what xmlbuilder is doing).
Just another example: the "&" character is not encoded as "&" example on runkit
{
"example": {
"#text": "A control character (backspace): \b"
}
}
may be converted to xml
<?xml version="1.0" encoding="UTF-8"?>
<example>A control character (backspace): \b</example>