更新时间:2022-10-22 14:55:44
实际上,由于一个问题,这是无效的XML:字符集。通常,这是你要做的纠正:
- 在你的文字之前添加以下 XML prolog :
<? xml version = 1.0 encoding = UTF-8 ?>
- 将文件保存为UTF-8。你可以随时以编程方式进行。
它会起作用,我测试过。您可以使用任何其他UTF(但不是任何过时的Unicode前编码),但UTF-8是Web事实上的标准,否则最合适。
请参阅:
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
Hi All,
I am reading a values from xml file for different languages.
Following is xml file contents :
<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>
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
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 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