我正在尝试从资源中读取XML,但它返回错误。这是我的代码;
string s = Properties.Resources.myXMLFile;
XDocument x = XDocument.Load(s);
错误信息如下;
An exception of type 'System.ArgumentException' occurred in mscorlib.dll but was not handled in user code
Additional information: Illegal characters in path.
单步执行代码,我可以在字符串s
中看到XML文件。在VS和其他XML解析器中打开文件,该文件不会出现任何错误。为什么会出现此错误?
答案 0 :(得分:2)
XDocument.Load()
期望包含XML文件路径的字符串作为参数。如果您将XML内容作为字符串,则应使用XDocument.Parse()
代替:
string s = Properties.Resources.myXMLFile;
XDocument x = XDocument.Parse(s);