Function to handle “Error Parsing XML: The entity name must immediately follow the ‘&’ in the entity reference” error

When following error is obtained:

“Error Parsing XML: The entity name must immediately follow the ‘&’ in the entity reference.”,

Use the escapeSpecialChar function

function escapeSpecialChar(textvalue) {


            try {
                textvalue = textvalue.replace(/&/g, '&');
                textvalue = textvalue.replace(/</g, '&lt;');
                textvalue = textvalue.replace(/>/g, '&gt;');
                textvalue = textvalue.replace(/'/g, '');
                textvalue = textvalue.replaceAll("$", "");
                log.debug('textvalue', textvalue)
                return textvalue;
            } catch (e) {
                log.error({
                    title: e.name,
                    details: e
                });
            }
        }

Leave a comment

Your email address will not be published. Required fields are marked *