473,770 Members | 5,569 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlDocument.Loa dXml 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><Fami lyName><FamilyN ames>David &amp; Karen</FamilyNames><Su rname>Adams</Surname></FamilyName></NameInfo>

When I try to load this up in a XmlDocument it blows up.

string xmlData = Request.Form["RequestDat a"];
dom.LoadXml(xml Data);

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>uSYzhMD9w0y by494o3XxHg==</Id>
Nov 12 '05 #1
2 8690
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><Fami lyName><FamilyN ames>David &amp; Karen</FamilyNames><Su rname>Adams</Surname></FamilyName></NameInfo>

When I try to load this up in a XmlDocument it blows up.

string xmlData = Request.Form["RequestDat a"];
dom.LoadXml(xml Data);

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><Fam ilyName><Family Names>David &amp;
Karen</FamilyNames><Su rname>Adams</Surname></FamilyName></NameInfo>";
doc.LoadXml(xml );
doc.Save(Consol e.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><Fami lyName><FamilyN ames>David &amp; Karen</FamilyNames><Su rname>Adams</Surname></FamilyName></NameInfo>

When I try to load this up in a XmlDocument it blows up.

string xmlData = Request.Form["RequestDat a"];
dom.LoadXml(xml Data);

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><Fam ilyName><Family Names>David &amp;
Karen</FamilyNames><Su rname>Adams</Surname></FamilyName></NameInfo>";
doc.LoadXml(xml );
doc.Save(Consol e.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
6016
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 another machine on the network (or using IE, Firefox, etc. on the same machine). Everything seems to work fine (no errors anywhere) and the web application is snappy as intended. However, at the end of the day when I turn off my dev machine,...
1
17137
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 characters like &#x1;. Using the CreateTextNode method I create a text node containing "\u0001a" (C# string literal notation). As far as I understand the DOM allows that and an implementation is not required to throw an error. When OuterXml is...
12
6328
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: <SomeChildElement type="c" href="There.aspx?id=5" /> But as soon as I change it to something like this: <SomeChildElement type="c" href="There.aspx?id=5&amp;t=m" />
5
3447
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; &lt;me@mydomain.com&gt;</Address> </Addresses>
0
917
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 base stored procedures. Could some one suggest the best way to achieve this - also if any good article to know more about this... Thanks Suhas
6
1778
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 ' ' (single quotes) make much difference to the way this code works? It is from a section of code
1
5070
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) { xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); namespaceManager = new
0
884
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 from the Visual C# Reference: Errors & Warnings section. When I get an error when creating an aspx file and press F1 I just get a general help concerning the Error List Window". I would like to know if there is something simmillar to VC#R:E&W in...
1
4165
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 and parse error. IMO, only thing that would cause exception is Malformed xml. right?
0
9592
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10059
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10005
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5452
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3972
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2817
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.