【发布时间】:2011-04-02 15:01:44
【问题描述】:
编码平台:使用 C# 的 ASP.NET WebForms 4.0
背景:我正在从 XML 中读取一些值,并且一切都在我的语言环境(en-US)中运行。 XML 看起来像这样
<?xml version="1.0" encoding="utf-32" ?>
<settings>
<UserRegistration>AutoAuthorize</UserRegistration>
<OpenIDProfile>PromptUser</OpenIDProfile>
<EnableSpamProtection>Yes</EnableSpamProtection>
<MaxAllowedOpenID>2</MaxAllowedOpenID>
<WebsiteURL>http://localhost:70707/blah/</WebsiteURL>
<FacebookOAuthURL>https://graph.facebook.com/oauth/authorize?</FacebookOAuthURL>
<FacebookAccessTokenURL>https://graph.facebook.com/oauth/access_token?</FacebookAccessTokenURL>
<FacebookRedirectPage>ausgefüllt.aspx</FacebookRedirectPage>
<FacebookAppID>192328104139846</FacebookAppID>
<FacebookAppKey>29daeb58d8ae84cc22181f4073e4ed9d</FacebookAppKey>
<FacebookAppSecret>b94e9ddd20efc47b3227e7333925fdd8</FacebookAppSecret>
<FacebookScope>email</FacebookScope>
<EmailSettingsDisplayName>admin</EmailSettingsDisplayName>
<EmailSettingsEmail>blah@blah.com</EmailSettingsEmail>
<EmailSettingsPassword>192185135098207157230060249027191124199097098215</EmailSettingsPassword>
</settings>
问题
我将整个东西打包给我的客户进行测试。测试环境是
服务器:Windows Server 2008 R2 64 位
语言环境:德语(de-DE)
现在,当我尝试读取 XML 时,Elmah 抛出两个错误错误。第一个错误是
System.Xml.XmlException: '????', 十六进制值 0xA000D,是一个 无效字符。第 1 行,位置 40. 在 System.Xml.XmlTextReaderImpl.Throw(字符串 水库,字符串 [] 参数)在 System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace() 在 System.Xml.XmlTextReaderImpl.ParseDocumentContent() 在 System.Xml.Linq.XDocument.Load(XmlReader 阅读器,LoadOptions 选项)在 System.Xml.Linq.XDocument.Load(字符串 uri,LoadOptions 选项)在 Administrator_SiteSettings.SaveSettingsButton_Click(对象 发件人,EventArgs e) 在 c:\Webs\ThirdPartyLogins\Administrator\SiteSettings.aspx.cs:line 48
我正在将这些 XML 节点值放入字典中,此错误之后是字典的键未找到错误。
编码是罪魁祸首吗?
我的代码可能有什么问题?
更新:请阅读UTF-8, UTF-16, and UTF-32。 更改为 utf-8 会有帮助吗?
Update2:有两件事可以更清楚地说明问题。
1) 将编码更改为 utf-16 时,出现新错误
在 utf-16 它的 System.Xml.XmlException: '.',十六进制值 0x00,是一个 无效字符。第 1 行,位置 39.
2) 之前粘贴的 XML 不完整。它有更多的节点和一些 URL 作为节点数据。这会是个问题吗?也更新了 XML。
【问题讨论】:
-
这似乎是一个编码问题。确定 XML 文件实际上是 UTF32 格式吗?
标签: c# asp.net xml encoding webforms