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

Numbering Table Parent group and child group ssrs report

 Recently I have faced a scenario to numbering parent group and subgroup in the following formate 10 parentGroupRow1    10.1 childGroupRow1 ...