Helper method for escaping XML, used by GGUS sync

For having a valid XML, in text and attribute values, you need to escape ASCII characters like:

"
"
<
  &lt;
>
 &gt;
&
&amp;

How

All text in an XML document will be parsed by the parser, but text inside a CDATA section will be ignored by the parser. So, instead of replace this four characters we put the text inside CDATA using the script include 'String-Util':

..
  /**
   * Escape the following characters to be transported over the network with XML
   *  - >
   *  - <
   *  - "
   *  - &
   */
  escapeXML: function(text) {
    return '<![CDATA[' + text.replace(']]>', ']]]]><![CDATA[>') + ']]>';
  },
..

Then, we used this method in GGUS sync to escape short description, solution and comments:

..
gs.include('String-Util');
var stringUtil = new StringUtil();
..
s.setParameter('short_description', stringUtil.escapeXML(current.short_description));
..

-- OmarPera - 28-Apr-2011

Edit | Attach | Watch | Print version | History: r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r1 - 2011-04-28 - unknown
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    Main All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright &© 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
or Ideas, requests, problems regarding TWiki? use Discourse or Send feedback