Unable to replace special character in Script include and Business Rules
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2010 08:54 AM
Hello All,
I am facing a problem in xml creation due to special characters. I am creating xml in script include by using parameters from business rule. There are some string which contains special symbol like (&,') .
To replace them with corresponding html name or html code I am using following code :
mystring.replace("&", "&") or mystring.replace("&", "&")
but , When I save this business rule, it changes the above line to
mystring.replace("&", "&");
Please suggest a way or approach to prevent this .

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2014 11:26 PM
It sounds like you are trying to modify a script include after-the-fact and save it?
If you want to encode strings for XML then you can use this:
JSUtil.escapeText(my_string);
- James
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2014 05:34 AM
HI ,
I tried to used both package call and JSUtil to escape, but it did not work
I got SAX Exception, prolog not allowed... please advise , below is the snippet:
var sm = new SOAPMessage('function1', 'Query');
sm.setStringParameter('id',id);
sm.setStringParameter('Code',Query);
sm.setStringParameter('Password','123');
sm.setStringParameter('Username','abc');
sm.post();
var k=1;
var response = sm.getResponse();
while (response == null) {
//gs.log("waiting for response ... " + k + " seconds");
response = sm.getResponse(1000);
k++;
if (k > 30) {
gs.print("validateClarityAjax Response exceeded 30 serc . " + k + " seconds");
status = "408"; // request timeout
response = "timed out waiting for SOAPProbe response, please check the ECC queue at a later time";
break; // service did not respond after 60 tries
}
}
gs.log('validateClarityAjax : Response:' +response);
// var clean=JSUtil.escapeText(response.toString());
var clean=Packages.org.apache.commons.lang.StringEscapeUtils.escapeXml(response.toString());
var xmldoc = new XMLDocument(clean);
projName=xmldoc.getNodeText("//name");
gs.log(projName);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2014 05:35 AM
HI ,
I tried to used both package call and JSUtil to escape, but it did not work
I got exception:
org.xml.sax.SAXParseException: Reference is not allowed in prolog.
Evaluator: java.lang.NullPointerException
.. please advise , below is the snippet:
var sm = new SOAPMessage('function1', 'Query');
sm.setStringParameter('id',id);
sm.setStringParameter('Code',Query);
sm.setStringParameter('Password','123');
sm.setStringParameter('Username','abc');
sm.post();
var k=1;
var response = sm.getResponse();
while (response == null) {
//gs.log("waiting for response ... " + k + " seconds");
response = sm.getResponse(1000);
k++;
if (k > 30) {
gs.print("validateClarityAjax Response exceeded 30 serc . " + k + " seconds");
status = "408"; // request timeout
response = "timed out waiting for SOAPProbe response, please check the ECC queue at a later time";
break; // service did not respond after 60 tries
}
}
gs.log('validateClarityAjax : Response:' +response);
// var clean=JSUtil.escapeText(response.toString());
var clean=Packages.org.apache.commons.lang.StringEscapeUtils.escapeXml(response.toString());
var xmldoc = new XMLDocument(clean);
projName=xmldoc.getNodeText("//name");
gs.log(projName);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2014 08:14 AM
Check the line "sm.setStringParameter('Code',Query);"
Probably "Query" should be quotes unless it is a variable declared earlier in the script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2014 08:54 AM
If you are creating XML that is ultimately being processed by jelly, you should substitute the ampersand with $[AMP] or ${AMP} (depending on which jelly pass you want it process on). Does this help?