Skip to content

Prevent encoding of #text values when XML is built #685

Closed Answered by gavinharriss
gavinharriss asked this question in Q&A
Discussion options

You must be logged in to vote

Unfortunately entities isn't exposed via the typescript definitions, but this is what worked for me in case anyone else has the same issue:

this.builder = new XMLBuilder({
    ignoreAttributes: false,
    // CargoWise only likes < and > chars encoded in text, so override encoding and provide our own encoder
    // NOTE: There appears to be an `entities` setting in js where we can set explicit chars to be encoded,
    //       but this doesn't seem to be exposed via the ts type definitions. 
    processEntities: false,
    tagValueProcessor: (tagName, a) => { 
        if (a) {
            return a.toString()
                .replace(/</g, '&lt;')
                .replace(/>/g, '&gt;');
   …

Replies: 4 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@gavinharriss
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@amitguptagwl
Comment options

@gavinharriss
Comment options

Answer selected by gavinharriss
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants