Unescape escapeXML text

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert Mark Bram

    Unescape escapeXML text

    Hi All,

    I have an application that is writing Javascript with JSP server side
    code that uses escapeXML:

    var someVar = "<c:out escapeXml="true " value="You'll never escape!"/
    >";
    How to I unescape this? Using the unescape() function doesn't cut
    it..
    unescape("You&# 039;ll never escape!");

    Do I have to use regex to replace or is there some other way?

    Thanks for any assistance!

    Rob
    :)
  • Bart Van der Donck

    #2
    Re: Unescape escapeXML text

    Robert Mark Bram wrote:
    I have an application that is writing Javascript with JSP server side
    code that uses escapeXML:
    >
    var someVar = "<c:out escapeXml="true " value="You'll never escape!"/
    ";
    >
    How to I unescape this? Using the unescape() function doesn't cut
    it. unescape("You&# 039;ll never escape!");
    >
    Do I have to use regex to replace or is there some other way?
    var txt = 'apostrophe &#039; / double quote: &#0034; / '
    + ' s: &#115; / รจ: &#232; / Chinese sign: 新';

    txt = txt.replace(/(&#)([0-9]{1,5})(;)/g,
    function (a1, a2, a3, a4) {
    return String.fromChar Code(a3);
    }
    );
    alert(txt);

    Hope this helps,

    --
    Bart

    Comment

    • dhtml

      #3
      Re: Unescape escapeXML text

      Robert Mark Bram wrote:
      Hi All,
      >
      I have an application that is writing Javascript with JSP server side
      code that uses escapeXML:
      >
      var someVar = "<c:out escapeXml="true " value="You'll never escape!"/
      >";
      >
      How to I unescape this? Using the unescape() function doesn't cut
      it..
      unescape("You&# 039;ll never escape!");
      >
      Or could escape it differently.

      If you are using struts you can use StringEscapeUti ls.escapeJavaSc ript.

      Would be really nice to have c:out handle that.

      Fictitious example:
      <c:out escapeJavaScrip t="true" value="You'll never escape!"/>

      Garrett
      >
      Rob
      :)

      --
      comp.lang.javas cript FAQ <URL: http://jibbering.com/faq/ >

      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: Unescape escapeXML text

        Robert Mark Bram wrote:
        I have an application that is writing Javascript with JSP server side
        code that uses escapeXML:
        >
        var someVar = "<c:out escapeXml="true " value="You'll never escape!"/>";
        *g*
        How to I unescape this?
        Maybe

        someVar = someVar.replace (/&lt;/g, "<").replac e(/&gt;/g, ">"
        .replace(/&amp;/g, "&");
        Using the unescape() function doesn't cut it..
        unescape("You&# 039;ll never escape!");
        It is not supposed to. unescape() decodes (ASCII) percent-encoded strings.
        It was primarily used to decode URI components, and is now deprecated in
        favor of decodeURI() and decodeURICompon ent(), which in addition can decode
        UTF-8 percent encoding.
        Do I have to use regex to replace or is there some other way?
        A regular expression like above would not help in your case because the
        escaping of `"' needs to take place *before* you insert the value with JSP,
        i.e. "on the server".

        You do not need `escapeXml="tru e"' if you declare the content of the XHTML
        `script' element CDATA, provided the string never contains `"', like
        in your example:

        <script type="text/javascript">
        // <![CDATA[
        ...
        ]]>
        </script>

        But if the `<' and `>' are your only problems, you could as well move the
        code to an external script file or simply use HTML instead.


        PointedEars
        --
        var bugRiddenCrashP ronePieceOfJunk = (
        navigator.userA gent.indexOf('M SIE 5') != -1
        && navigator.userA gent.indexOf('M ac') != -1
        ) // Plone, register_functi on.js:16

        Comment

        • Robert Mark Bram

          #5
          Re: Unescape escapeXML text

          Thanks to all for the input!

          Comment

          Working...