tags:

views:

196

answers:

5

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? thanks.

+6  A: 

Try escaping it with &amp;.

Li0liQ
+1  A: 

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;

anon
+3  A: 

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

Brian Agnew
A: 

To escape an ampersand:

&amp;
jaywon
+2  A: 

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.

John Saunders
+1 for the caveat about creating XML via standard string manipulation
Brian Agnew
Edward Ross
XML Can be created by hand, by using an XML-based API, like `XmlWriter` in .NET. This completely avoids this problem, and is what I'm referring to.
John Saunders
@Downvoters: does my edit address your concerns?
John Saunders