Groups | Blog | Home
all groups > dotnet xml > june 2004 >

dotnet xml : XmlDocument.LoadXml Errors with &amp in string


Eric Zechman via .NET 247
6/5/2004 12:21:40 PM
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 &amp; 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 &amp; with a + or something like that. But every diferent way I try to load the string blows up.


--------------------------------
From: Eric Zechman

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

Oleg Tkachenko [MVP]
6/6/2004 1:25:19 PM
[quoted text, click to view]

I can't reproduce the problem, the following code works just fine:

XmlDocument doc = new XmlDocument();
string xml = "<NameInfo><FamilyName><FamilyNames>David &amp;
Karen</FamilyNames><Surname>Adams</Surname></FamilyName></NameInfo>";
doc.LoadXml(xml);
doc.Save(Console.Out);

Debug and inspect what xmlData value really is.
--
Oleg Tkachenko [XML MVP]
AddThis Social Bookmark Button