开发者

XML '&' character causing problems

开发者 https://www.devze.com 2022-12-13 07:11 出处:网络
A semi colon character was expected. Error processing resource \'... <key>SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\CNXT_MODEM_PCI_VEN_8086&DEV

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

精彩评论

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

关注公众号