I have a project in which I get xml posted via a hidden form field (data=<xml></xml>). People are entering names like Bill & Sandy Smith. this is coming over as:
<NameInfo><FamilyName><FamilyNames>David & Karen</FamilyNames><Surname>Adams</Surname></FamilyName></NameInfo>
When I try to load this up in a XmlDocument it blows up.
string xmlData = Request.Form["RequestData"];
dom.LoadXml(xmlData);
results with this:
"This is an unexpected token. The expected token is 'EndElement'. Line 1, position 1022."
I really don't want to go and put some hack in like replacing any & with a + or something like that. But every diferent way I try to load the string blows up.
> I have a project in which I get xml posted via a hidden form field (data=<xml></xml>). People are entering names like Bill & Sandy Smith. this is coming over as:
> <NameInfo><FamilyName><FamilyNames>David & Karen</FamilyNames><Surname>Adams</Surname></FamilyName></NameInfo>
[quoted text clipped - 6 lines]
> results with this:
> "This is an unexpected token. The expected token is 'EndElement'. Line 1, position 1022."
I can't reproduce the problem, the following code works just fine:
XmlDocument doc = new XmlDocument();
string xml = "<NameInfo><FamilyName><FamilyNames>David &
Karen</FamilyNames><Surname>Adams</Surname></FamilyName></NameInfo>";
doc.LoadXml(xml);
doc.Save(Console.Out);
Debug and inspect what xmlData value really is.

Signature
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com