Click here to Skip to main content
13,552,693 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 15-Mar-13 0:38am
Updated 17-Apr-17 13: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.
  Permalink  

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 |
Web01 | 2.8.180515.1 | Last Updated 17 Apr 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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