Announcement

Collapse

Mirth Connect 3.12.0 Released!

Mirth Connect 3.12.0 is now available as an appliance update and on our GitHub page. This release includes database performance improvements, improves visual HL7 representation, message pruning, keystore handling, PDF generation, community contributions, and fixes several security vulnerabilities. This release also contains many improvements to commercial extensions. See the release notes for the list of fixes and updates.

Download | See What's New | Upgrade Guide | Release Notes

For discussion on this release, see this thread.
See more
See less

Encoding Issue - Javascript ReplaceAll (RESOLVED)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Encoding Issue - Javascript ReplaceAll (RESOLVED)

    Hello everyone,
    I have created a SOAP Sender that sends its response to a channel reader. The web service is correctly invoked and returns data to this channel. However, there is a CDATA section in the response which appears to be encoded, resulting in a bunch of lt and gt tags in my message.


    When i put this into a message tree, these tags appear on one line and elements are not easily accessible. The easiest thing for me to do would be to create a preprocessor that replaces all lts and gts with < and > respectively. However, when i use the replace function, only the first lt and first gt are replaced. (please note that in the following examples i am leaving out a

    Code:
    return message.replace('&lt','<').replace('&gt','>');
    I would like to use a replaceAll function, but i receive an error message when i run the following:

    Code:
    return message.replaceAll("&lt","<").replaceAll("&gt",">");
    The error message says "Message payload is of type: java.lang.String". I am aware that there is a difference between a java string and a javascript string, but i'm not sure which replace function is suitable for my task.

    Any help would be greatly appreciated,
    Thanks
    Jason

    Post edited by: jason.irwin, at: 08/01/2008 09:51

  • #2
    Re:Encoding Issue - Javascript ReplaceAll

    I managed to solve this myself and thought I would post the solution in case anyone else runs into this problem. Here's the preprocessor script

    Code:
    return message.replace(/&lt/g,'<').replace(/&gt/g,'>');
    Again, please note that i have removed the semi-colon after lt and gt to allow the script to display properly on this forum

    Comment


    • #3
      Re:Encoding Issue - Javascript ReplaceAll

      I've run into a similar problem, but I just read this post ...

      There are two JS functions that seems to be designed for this:

      urlencode and urldecode.

      In order to avoid to extract the CDATA block and perform N replacements, you can try to do an urldecode of this block. But inmy scenario I've found many errors because the XML tags are name like "<PID.1>" and the E4X doesn't like the "." inside the tag-name.

      Comment

      Working...
      X