开发者

XML '&' character causing problems

A semi colon character was expected. Error processing resource '...

<key>SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\CNXT_MODEM_PCI_VEN_8086&DEV

How can I avoid this error being printed out when viewing my XML file in a browser? It seems to complain because of the '&' character, how do I escape it? thank开发者_如何转开发s.


Try escaping it with &amp;.


The & character should be escaped as &amp;, as per the XML standard. See this SO question for more info.


You need to use the character entity &amp;You will also probably experience issues with the open angle bracket, which needs to be encoded as &lt;


How did you create such XML? I bet you created it using string manipulation, as no self-respecting XML API would have produced such invalid XML.

This is why to create XML using XML APIs instead of string APIs.


var keyElement = new XElement(
    "key", @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\CNXT_MODEM_PCI_VEN_8086&DEV");

Problem solved.


To escape an ampersand:

&amp;


I had same issue and fixed it by using the following:

translate(replace(replace(TaskType),'&',' '),' > & < / \ " - ''',' ') 

it removed all & and hyphen characters. I believe XML does not like those characters.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜