Escaping ampersand character with following semicolon #169
-
Following code const xmlbuilder = require('xmlbuilder2');
const xml = xmlbuilder.create({ encoding: 'UTF-8' })
.ele('root').txt('5&ABC;')
.end({ prettyPrint: true });
console.log(xml); outputs <?xml version="1.0" encoding="UTF-8"?>
<root>5&ABC;</root> Is it expected that |
Beta Was this translation helpful? Give feedback.
Answered by
mglanville
Nov 16, 2023
Replies: 1 comment 1 reply
-
I think the problem is the way that xmlbuilder2 tries to avoid double-encoding XML escape sequences. Your string is being treated as an XML entity by nonEntityAmpersandRegex so the ampersand doesn't get replaced. I'm currently hitting a problem with the same code, but that's because I wan't the ampersand in the text |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Quty
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think the problem is the way that xmlbuilder2 tries to avoid double-encoding XML escape sequences. Your string is being treated as an XML entity by nonEntityAmpersandRegex so the ampersand doesn't get replaced.
I'm currently hitting a problem with the same code, but that's because I wan't the ampersand in the text
b&w
to be encoded and xmlbuilder2 seems to have been deliberately built to not do that.