XML encoding a string in JavaScript

Via SearchDomino and Ronald Pijper:XML encoding a string: XML strings must be encoded to conform to standards. Unfortunately, in Domino there are no XML encoding functions like @URLEncode.

The code is a JavaScriptLotusScript version of this function. It encodes the five specific entities into their XML encoded ones. For all characters outside of the basic ACII, set it to encode these with the character code.

Update:Rich Schwartz correctly points out that the code was LotusScript. That’s what I get for doing a quick blog post (before dashing out to dinner) with out trying the code myself. Interestingly the SearhDomino guys changed their post, after, to reflect that it was LotusScript. My bad.

One Reply to “XML encoding a string in JavaScript”

  1. I think you meant “LotusScript” rather than JavaScript in the title of this post.

    Also, I think you need to put a CDATA block around your code sample. Viewed in a browser, the case statement looks wrong because the browser is translating the entity values into characters, which makes it look like the statements aren’t really doing anything.

    Lastly, I think it’s probably necessary to use the Uni() function rather than the Asc() in the output stage, because XML entity values should be Unicode not ASCII. It’s probably better to use Uni() in the if test, too, although whether that’s really necessary depends on what your input source is.

    -rich schwartz

Leave a Reply