Reputation: 81
In my application there is a requirement to remove special characters from a string. I am able to achieve this by reading a string of special chars from config appsettinf key-value pair.
EX :
<appSettings>
<add key="ExcludeSpecialChars" value ="%'^"/>
</appSettings>
I am facing problem when I include & in the value ex :
key="ExcludeSpecialChars" value ="&%'^"
The application fails to build and shows an error "cannot parse the entity".
Is there any workaround so that I can include &
in the special chars string?
Upvotes: 6
Views: 1775
Reputation: 63065
Some characters have a special meaning in XML.
If you place a character like "&" inside an XML element, it will generate an error because the parser interprets it as the start of a new element.
you can use &
there are 5 predefined entity references in XML
< < less than
> > greater than
& & ampersand
' ' apostrophe
" " quotation mark
ref :http://www.w3schools.com/xml/xml_syntax.asp
Upvotes: 5
Reputation: 16596
Since .NET .config files are XML, use the entity &
to represent an ampersand:
<appSettings>
<add key="ExcludeSpecialChars" value ="&%'^"/>
</appSettings>
Upvotes: 6