Solved

problem with & in xml document

Posted on 2010-09-21
4
271 Views
Last Modified: 2012-05-10
I have a problem while tried to deserialize a XML file that contains a special character '&'. The error message is “An error occurred while parsing EntityName. Line 14, position 40.”

public static CSettings ReadSettings()

{

    CSettings ob = null;

    xmlFile = Path.Combine(CDCPath.LocalSystemConfig, SETTINGS_FILE_NAME);

    if (System.IO.File.Exists(xmlFile))

    {              

        Stream stream = new FileStream(xmlFile, FileMode.Open, FileAccess.Read, FileShare.Read);

        System.Xml.XmlReader streamReader = System.Xml.XmlReader.Create(stream);

        System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer

                    (typeof(CSettings));

        ob = (CSettings)serializer.Deserialize(streamReader);

        stream.Close();

    }            

    return ob;

}

Open in new window

0
Comment
Question by:Borsec
  • 2
4 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 33723485
can u post the xml?
0
 
LVL 3

Accepted Solution

by:
CyberSoft earned 500 total points
ID: 33741916
Make sure your XML does not simply contain the & but that it contains the entity &amp; - also you cannot have non-alpha-numeric characters in XML nodes and attributes - only contained within <[CDATA[  ]]> sections.

HTH
0
 

Author Comment

by:Borsec
ID: 33751371
Thanks! The problem is solved.
You're right, I found an simple '&'  in my XML file.
0
 
LVL 3

Expert Comment

by:CyberSoft
ID: 33751583
Great. Please mark this question as answered :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now