Click here to Skip to main content
15,880,405 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi All,
I am reading a values from xml file for different languages.
Following is xml file contents :
XML
<lang>
<FirstName>Prénom</FirstName>
<LastName>Nom de famille</LastName>
<UserName>L'identification d'email</UserName>
<Password>mot de passe</Password>
<confirmPassword>Confirmez mot de passe</confirmPassword>
</lang>


C#
if (File.Exists(fileName))
            {
                XmlTextReader textRead = new XmlTextReader(fileName);
                XmlDocument document = new XmlDocument();
                document.Load(textRead);

                XmlNodeList node = document.SelectNodes("lang");
            }

when I am trying to read this file from C# it is showing an error in XML file also when I am trying to open xml file in browser it is showing an error.

What is the issue here !!

Please suggest..
Thanks in advance for your suggestions...

--Avinash
Posted
Comments
Timberbird 18-Oct-13 8:44am    
Have you tried adding XML header with encoding attribute?
Sergey Alexandrovich Kryukov 18-Oct-13 11:50am    
This is called "prolog". If you meant that, this is a right idea. Please see my answer.
—SA

1 solution

Indeed, this is the invalid XML due to one problem: a character set. Typically, this is what you do to correct it:
  • Add the following XML prolog before your text:
    XML
    <?xml version="1.0" encoding="UTF-8"?>

  • Save your file in UTF-8. You can always do it programmatically.


It will work, I tested. You can use any other UTF (but not any of the obsolete pre-Unicode encodings), but UTF-8 is the Web de-facto standard and most appropriate otherwise.

Please see:
http://www.w3.org/TR/2000/REC-xml-20001006#sec-prolog-dtd[^],
http://en.wikipedia.org/wiki/Unicode[^],
http://www.unicode.org/faq/utf_bom.html[^].

—SA
 
Share this answer
 
v2
Comments
thatraja 18-Oct-13 11:27am    
Right, 5!
Sergey Alexandrovich Kryukov 18-Oct-13 11:48am    
Thank you, Raja.
—SA
Avinash6474 18-Oct-13 23:54pm    
Thank you
Sergey Alexandrovich Kryukov 19-Oct-13 0:51am    
You are welcome.
—SA

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900