Load XML document in Windows CE using C #
I´m trying to load a XML document in Windows CE using C#, however i keep getting some strange errors in debugging. Here is my code:
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;
}
}
}
Am I doing something wrong? The XML file is in the right place, and I've tried several locations for the file. This is the error I'm getting.
{"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"}
The error occurs when I load the XML file:
docXML.Load(Environment.GetFolderPath(Environment.SpecialFolder.Programs)+"\modulos.xml");
Here is the exception detail:
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()
---------------EDIT--------------
It took me a while but now I have real error reports :)... Here is the actual error.
"System does not support 'iso-8859-1' encoding. Line 1, position 31."
I've tried saving my file with different encodings but i keep on getting the same error. Any solutions?
---------------EDIT----------------- I've solved it :D . I was changing the encoding using notepad, but i forgot I had written an encoding tag in the XML file, and that was causing this problem. Stupid mistake. :(
Well, actually you have to talk with the one that built your WinCE OS image to include also the ".Net Compact Framework 3.5 Localized String Resources" by default you will have en-US, but you can select also something else, for example: Portuguese. The option is in Catalog Items View -> Core OS -> Windows Embedded Compact -> Applications and Services Development -> .NET Compact Framework 3.5 -> .Net Compact Framework 3.5 -> .Net Compact Framework 3.5 Localized String Resources
See attached picture:
You will have to remake the OS image and also the SDK if you are using one. After this you should no longer have this error.
Are you actually attached with the debugger? I ask becasue of the fact that you don't have exception messages available. Those get deployed automatically when you are debugging (the CAB file is NETCFv35.Messages.EN.cab found at C:\Program Files (x86)\Microsoft.NET\SDK\CompactFramework\v3.5\WindowsCE\Diagnostics
).
What we do know is that it's an XmlException, so it has nothing to do with the file location or it being locked (you'd get a different type of exception is that case). Most likely you have invalid or malformed XML in the file you're trying to load. You'd have to post the XML itself for use to know exactly, but as a test, simply replace your file with a simple XML file containing just a definition and a root node and see what happens.
精彩评论