EDIT: I have edited my post...
Working on a project (c#), I have a string (password) within an XML file (app.config) which it value contains '&' character. Suppose it some thing like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="MainConnectionString" value="Data So开发者_如何学JAVAurce=MyDataSource;InitialCatalog=MyInitialCatalog;User ID=MyUserID;Password=ynhub&59=k31!890" />
</appSettings>
</configuration>
But compiler shows me an error and a squiggly blue line appears under 59 indicates that 'character 5 hexadecimal value is illegal in an XML name'
How can I remove this error?
Use "&
".
XML starts special characters with an & character, i.e. the famous &, < (<) and > (>).
For this reason you cannot use & in your XML without converting it to &. For example even in HTML links it's not allowed (but still common) to write:
<a href="foo.php?foo=bar&bar=baz">
It has to be written as:
<a href="foo.php?foo=bar&bar=baz">
Noone is doing it but HTML & XML specify it that way and especially XML is very strict about it.
The & you're thinking of isn't part of the string - it's part of your source code. Carefully read the code, paying careful attention to the position of any quote marks...
精彩评论