473,387 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 8663
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Don Miller | last post by:
I've been extensively modifying a web application (ASP, COM+) to take advantage of the XMLHTTP object for asynchronous requests (e.g. Ajax) on my dev machine (Win2KPro). I test the application from...
1
by: Martin Honnen | last post by:
With both .NET 1.0 and 1.1 I have found the following strange behaviour where System.Xml.XmlDocument.LoadXml doesn't throw an error when parsing a text node with a character reference to an invalid...
12
by: ~~~ .NET Ed ~~~ | last post by:
Hi, I have a standalone XML file (with the appropriate xml document header) that works fine when I load it using XmlDocument. I can have child elements like this without problems: ...
5
by: martin | last post by:
Hi, I would be extremly grateful for some help on producing an xml fragemt. The fragment that I wish to produce should look like this <Addresses> <Address>&qout;Somebody's Name&quot;...
0
by: Suhas Vengilat | last post by:
Hi, I am working on an ASP.Net (2.0) application with SQL 2K5. We need to display customised error messages for both business validation errors from the C# components as well as from the data...
6
by: Cerebral Believer | last post by:
Hi folks, I am having trouble identifying the error here can anyone help? Parse error: syntax error on line 318 $e-mail_1 = $_POST; Also will my use of " " (double quotes) instead of ' '...
1
by: Bruce Sandeman | last post by:
Hi, Is anyone able to help me? I have the following code and when I try to create an XPathNavigator object it keeps returning null. any cunning ideas? private void loadXMLDoc(String xml) {...
0
by: Woodchuck | last post by:
Hi:) I'm starting to create a ASP.NET website in VS 2005 after some experiance in C# programming. When I got an error while programming in C# and I pressed F1 I got an article explaining the error...
1
by: GeezerButler | last post by:
According to msdn, this method throws XmlException when "There is a load or parse error in the XML. In this case, the document remains empty." I cannot understand the difference between load...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.