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:
" |
" |
< |
< |
> |
> |
& |
& |
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
Topic revision: r1 - 2011-04-28
- unknown