Thursday, 14 January 2016

Encode Xml Special Character (<,>,',",&) in javaScript and C#

These special character (<,>,',",&) will be encode first when making xml because on these special character the xml will broke.
The below function is used when string containing the above special character,

function specialXmlCharacterEncode(str) {
    return String(str)
            .replace(/&/g, '&amp;')
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&apos;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;');
}


In C# this line of code is used when string containing  special character and you make xml query and use string in xml query like in fetchXml query.

 string  str =  SecurityElement.Escape(str);

No comments:

Post a Comment

Read only field , get latest value from read only field in in power app portal

Below line is used to make field readonly in power app portal through js $( "#bdo_relationshiprole_name" ).parent().css( "po...