gpt4 book ai didi

c# - 使用 C# 在 Windows CE 中加载 XML 文档

转载 作者:行者123 更新时间:2023-11-30 22:35:24 46 4
gpt4 key购买 nike

我正在尝试使用 C# 在 Windows CE 中加载 XML 文档,但是我在调​​试过程中不断遇到一些奇怪的错误。这是我的代码:

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace cpap3
{
public class Program
{
public static void Display()
{

XmlDocument docXML = new XmlDocument();

docXML.Load(Environment.GetFolderPath(Environment.SpecialFolder.Programs)+"\\modulos.xml");


XmlElement nodRoot = docXML.DocumentElement;

XmlNodeList nodItems = nodRoot.GetElementsByTagName("Modulos");

for (int i = 0; i < nodItems.Count; i++)
Console.WriteLine(nodItems[i].InnerXml);

for (int i = 0; i < nodItems.Count; i++)
Console.WriteLine(nodItems[i].InnerXml);

}

static int Main(string[] args)
{

Display();

return 0;
}
}
}

我做错了什么吗? XML 文件位于正确的位置,我已经为该文件尝试了多个位置。这是我得到的错误。

{“无法显示错误消息,因为找不到包含它的可选资源程序集 An error message cannot be displayed because an optional resource assembly containing it cannot be found”

加载XML文件时出现错误:

docXML.Load(Environment.GetFolderPath(Environment.SpecialFolder.Programs)+"\modulos.xml");

这是异常的详细信息:

System.Xml.XmlException was unhandled
Message="An error message cannot be displayed because an optional resource assembly containing it cannot be found An error message cannot be displayed because an optional resource assembly containing it cannot be found"
LineNumber=1
LinePosition=31
SourceUri="file:///Windows/Programs/modulos.xml"
StackTrace:
at System.Xml.XmlTextReaderImpl.Throw()
at System.Xml.XmlTextReaderImpl.Throw()
at System.Xml.XmlTextReaderImpl.CheckEncoding()
at System.Xml.XmlTextReaderImpl.ParseXmlDeclaration()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlLoader.Load()
at System.Xml.XmlDocument.Load()
at System.Xml.XmlDocument.Load()
at ConsoleApplication3.Program.Display()
at ConsoleApplication3.Program.Main()

----------------编辑----------------

这花了我一段时间,但现在我收到了真正的错误报告 :)...这是实际错误。

"System does not support 'iso-8859-1' encoding. Line 1, position 31." 

我试过用不同的编码保存我的文件,但我总是遇到同样的错误。任何解决方案?

----------------编辑----------------我已经解决了 :D 。我正在使用记事本更改编码,但我忘记了我在 XML 文件中写了一个编码标记,这导致了这个问题。愚蠢的错误。 :(

最佳答案

好吧,实际上你必须与构建你的 WinCE 操作系统镜像的那个人交谈,默认情况下你将拥有 en-US,但你也可以选择其他东西,例如:葡萄牙语。该选项位于目录项 View -> 核心操作系统 -> Windows Embedded Compact -> 应用程序和服务开发 -> .NET Compact Framework 3.5 -> .Net Compact Framework 3.5 -> .Net Compact Framework 3.5 本地化字符串资源

见附图: Catalog Item View

如果您正在使用,则必须重新制作操作系统镜像和 SDK。在此之后你应该不会再有这个错误。

关于c# - 使用 C# 在 Windows CE 中加载 XML 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7443763/

46 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com