Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / June 2004

Tip: Looking for answers? Try searching our database.

XmlDocument.LoadXml Errors with &amp in string

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Eric Zechman - 05 Jun 2004 20:21 GMT
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.
Oleg Tkachenko [MVP] - 06 Jun 2004 12:25 GMT
> 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>
[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 &amp;
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.