user105033
user105033

Reputation: 19568

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

Upvotes: 5

Views: 10929

Answers (6)

Aamir
Aamir

Reputation: 1

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.

Upvotes: -1

John Saunders
John Saunders

Reputation: 161773

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.

Upvotes: 3

jaywon
jaywon

Reputation: 8234

To escape an ampersand:

&amp;

Upvotes: 0

Brian Agnew
Brian Agnew

Reputation: 272207

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

Upvotes: 4

anon
anon

Reputation:

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;

Upvotes: 3

Li0liQ
Li0liQ

Reputation: 11254

Try escaping it with &amp;.

Upvotes: 12

Related Questions