Click here to Skip to main content
13,829,388 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hello All,

I have got an exception while parsing an XML string.

Here is the exception an error occurred while parsing entityname;. line 1 and the XML I have used is as follows ;
<Details CompanyName="Outlook & Outlook Express" ></Details>
The code is given below :
StringReader strRdr = new StringReader(textBox1.Text);
XmlDocument xmlDoc = new XmlDocument();
try
{
    xmlDoc.Load(strRdr);
    XmlNode node = xmlDoc.DocumentElement.SelectSingleNode(@"/Details");
}
catch (Exception Ex)
{
    System.Windows.Forms.MessageBox.Show(Ex.Message.ToString(), "XML Parsing");
}


If someone can help me to solve this issue, that would be great.

Regards
Sebastian
Posted
Updated 17-Apr-17 14:04pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

It is because of & in the company name. When the string is being loaded in the XMLDocument it throws the error.

You need to encode it before loading it up. Following should do:
StringReader strRdr = new StringReader("<Details CompanyName=\"Outlook &amp; Outlook Express\" ></Details>");

If needed, decode it back when needed.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.190114.1 | Last Updated 17 Apr 2017
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100