Solved

problem with & in xml document

Posted on 2010-09-21
4
269 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

13 Experts available now in Live!

Get 1:1 Help Now