472,097 Members | 1,045 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,097 software developers and data experts.

XmlDocument.LoadXml Errors with &amp in string

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/)

<Id>uSYzhMD9w0yby494o3XxHg==</Id>
Nov 12 '05 #1
2 8570
Eric Zechman via .NET 247 wrote:
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 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]
http://blog.tkachenko.com
Nov 12 '05 #2
Eric Zechman via .NET 247 wrote:
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 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]
http://blog.tkachenko.com
Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Don Miller | last post: by
1 post views Thread by Martin Honnen | last post: by
12 posts views Thread by ~~~ .NET Ed ~~~ | last post: by
5 posts views Thread by martin | last post: by
6 posts views Thread by Cerebral Believer | last post: by
1 post views Thread by Bruce Sandeman | last post: by
reply views Thread by Woodchuck | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.