Topic
8 replies Latest Post - ‏2013-02-15T12:02:39Z by HermannSW
SystemAdmin
SystemAdmin
6772 Posts
ACCEPTED ANSWER

Pinned topic Special character (&,<,>,") escaping in Datapower

‏2013-02-01T11:47:54Z |
Hi,
My requirement to escape special characters such as &,<,>," etc in response.
Only & and < are getting escaped by default to &amp and &lt. But > and " are not getting escaped.
I added a new compilation policy in xml manager, that also didnt work.
Referred a thread http://www.ibm.com/developerworks/forums/message.jspa?messageID=14873703, but not much info about it.
Could someone please shed a light on Special character escaping in Datapower.
Updated on 2013-02-15T12:02:39Z at 2013-02-15T12:02:39Z by HermannSW
  • HermannSW
    HermannSW
    4372 Posts
    ACCEPTED ANSWER

    Re: Special character (&#38;,&lt;,&gt;,") escaping in Datapower

    ‏2013-02-01T12:02:54Z  in response to SystemAdmin
    Hi Sathish,

    according the spec http://www.w3.org/TR/REC-xml/#syntax only '<' and '&' have to be escaped.

    While you can control that some characters different to '<' and '&' should not be escaped (by a Minimum Output Escaping rule)
    there is no option to ask Datapower to escape '>'.

    Why would you want to escape it?
    Any compliant XML processor does handle '>' and '&​gt;' the same.

     
    Hermann<myXsltBlog/> <myXsltTweets/>
    • SystemAdmin
      SystemAdmin
      6772 Posts
      ACCEPTED ANSWER

      Re: Special character (&#38;,&lt;,&gt;,") escaping in Datapower

      ‏2013-02-13T12:35:11Z  in response to HermannSW
      Hi,
      Sorry for delayed response. That was my client vendor's requirement.
      I tried with CDATA aswell. If I pass > to DP, its output would be &gt;, but expected output would be >
      Could you please let me know is there any way to do it.
      • HermannSW
        HermannSW
        4372 Posts
        ACCEPTED ANSWER

        Re: Special character (&#38;,&lt;,&gt;,") escaping in Datapower

        ‏2013-02-14T09:22:03Z  in response to SystemAdmin
        Hi,

        > Sorry for delayed response. That was my client vendor's requirement.
        >
        that requirement just shows us that their system is NOT a compliant XML processing system.

        But anyway, find below a DataPower solution to achieve what you want -- it is ALWAYS bad practice to generate XML output as text -- but if you really need ...
        
        $ echo 
        "<foobar/>" | coproc2 escape.xsl - http:
        //dp3-l3:2223; echo abc&​amp;&​lt;&​gt;&​quot;123 $ $ cat escape.xsl <xsl:stylesheet version=
        "1.0" xmlns:xsl=
        "http://www.w3.org/1999/XSL/Transform" xmlns:regexp=
        "http://exslt.org/regular-expressions" > <xsl:output method=
        "text"/>   <xsl:variable name=
        "toEscape">abc<![CDATA[&<>
        "]]>123</xsl:variable>   <xsl:template match=
        "/"> <xsl:value-of select=
        "regexp:replace( regexp:replace( regexp:replace( regexp:replace( $toEscape, 
        '&amp;',
        '',
        '&amp;amp;' ), 
        '&lt;',
        '',
        '&amp;lt;' ), 
        '&gt;',
        '',
        '&amp;gt;' ), 
        '&quot;',
        '',
        '&amp;quot;' )
        "/> </xsl:template>   </xsl:stylesheet> $
        


         
        Hermann<myXsltBlog/> <myXsltTweets/>
        • SystemAdmin
          SystemAdmin
          6772 Posts
          ACCEPTED ANSWER

          Re: Special character (&#38;,&lt;,&gt;,") escaping in Datapower

          ‏2013-02-14T12:44:25Z  in response to HermannSW
          Hi,
          Thanks for the reply. But I need output as xml format.
          I need > as output if I pass > or > as input in the request.
          Could you please have a look and let me know how we can achieve this.

          Regards,
          Sathish M
          • HermannSW
            HermannSW
            4372 Posts
            ACCEPTED ANSWER

            Re: Special character (&#38;,&lt;,&gt;,") escaping in Datapower

            ‏2013-02-14T12:50:34Z  in response to SystemAdmin
            Hi,

            please add {(#8203;code}...{​code} around what you post when its critical (like amp or lt entities).

            Please use "Preview" before posting to make sure that what you post looks the way you want.
            This allows you to correct postings before submitting -- editing afterwards is impossible.

            Sorry, I do not get what your requirement is, you stated differently above.
            Please attach a sample file you want to retrieve as output, with explanation what are the specific needs there.

             
            Hermann<myXsltBlog/> <myXsltTweets/>
            • HermannSW
              HermannSW
              4372 Posts
              ACCEPTED ANSWER

              Re: Special character (&#38;,&lt;,&gt;,") escaping in Datapower

              ‏2013-02-14T12:51:39Z  in response to HermannSW
              Sorry, {​code}...{​code} around ...
              • SystemAdmin
                SystemAdmin
                6772 Posts
                ACCEPTED ANSWER

                Re: Special character (&#38;,&lt;,&gt;,") escaping in Datapower

                ‏2013-02-15T10:40:21Z  in response to HermannSW
                Hi,
                Format got changed after posting. Please find the attache file in which I mentioned the requirement.
                Request xml contains special character and we need to escape that special character in response (for synchronous call).
                Please shed some light and let me know if we can escape.
                I tried in different xsl's but no luck.
                • HermannSW
                  HermannSW
                  4372 Posts
                  ACCEPTED ANSWER

                  Re: Special character (&#38;,&lt;,&gt;,") escaping in Datapower

                  ‏2013-02-15T12:02:39Z  in response to SystemAdmin
                  Find a partial solution attached -- strange requirement --> strange solution, sorry.

                  $ coproc2 escape2.xsl MessageID.xml http://dp2-l3:2223 ; echo
                  <request xmlns:pre="urn:blah" att="123">
                    <RelatesToMessageID>abc&​gt;pqr<RelatesToMessageID>
                    <stuff xmlns:pre2="urn:x" xmlns:pre="urn:blah" att2="123">123</stuff>
                  </request>
                  $ 
                  $ cat MessageID.xml 
                  <request xmlns:pre="urn:blah" att="123">
                    <MessageID>abc>pqr</MessageID>
                    <stuff xmlns:pre2="urn:x" att2="123">123</stuff>
                  </request>
                  $ 
                  $ xpath++ "/comment()" escape2.xsl
                  <!-- 
                       this strange serializer is only needed because of strange requirement
                       
                       this serializer is not complete, find a complete one here:
                       http://www.biglist.com/lists/lists.mulberrytech.com/xsl-list/archives/201008/msg00186.html
                   
                       you cannot use <dp:serialize> here.
                  -->
                  $
                  


                  Hermann <myXsltBlog/> <myXsltTweets/>
                  Updated on 2014-03-25T02:39:50Z at 2014-03-25T02:39:50Z by iron-man