xmldoc
xmldoc copied to clipboard
toString() adds extra rows that were never there; Also deletes first line in file.
toString() adds extra rows that were never there; Also deletes first line in file.
I tried the options indicated in the readme file, but compressed literally compressed all into one line, preserveWhiteSpace added 2 lines between each node, and trimmed does not seem to affect anything.
Original format:
<?xml version='1.0' encoding='utf-8'?>
<parent>
<node></node>
</parent>
Output Format:
<parent>
<node></node>
</parent>
Hi! toString() isn't designed to preserve the entire original document, it's just for debugging. But it should still work for most cases, you'll just need to add back the <?xml… declaration yourself.
I don't see those extra lines though, when I run your example:
var xmlString = `
<?xml version='1.0' encoding='utf-8'?>
<parent>
<node></node>
</parent>
`.trim();
var parsed = new XmlDocument(xmlString);
var result = parsed.toString()
console.log(result);
It prints:
<parent>
<node/>
</parent>
I'm also seeing extra line breaks added - I'm on a Mac if that helps.
Preserving whitespace works only when combined with compressed:
toString({ compressed: true, preserveWhitespace: true }).
Without compressed it would add extra line breaks even if they are already there. The code from above prints the following for me (Ubuntu/WSL):
<parent>
<node/>
</parent>
I experience the issue described in this ticket.