所以我是C#总noob有没有什么办法使这项工作? 如果有人能解释为什么我的系统无法正常工作,以及为什么会有另一个版本,这也将是一个很大的帮助。有没有什么办法可以让我的C#XMLManager工作?
using System;
using System.Xml;
public class XMLManager
{
private XmlTextReader reader;
private XmlDocument document;
private XmlNodeList nodeList;
public void OpenFile(string file)
{
try
{
reader = new XmlTextReader(file);
reader.WhitespaceHandling = WhitespaceHandling.None;
reader.MoveToContent();
document = new XmlDocument();
document.Load(reader);
nodeList = document.SelectNodes(@"Settings/Settings");
}
catch (System.IO.FileNotFoundException)
{
}
}
public void CloseFile()
{
if (reader != null)
{
((IDisposable)reader).Dispose();
reader.Close();
reader = null;
}
document = null;
nodeList = null;
}
public string Get(string attrib)
{
for (int i = 0; i < nodeList.Count; i++)
{
reader.MoveToAttribute(i);
if (reader.Name == attrib)
{
return reader.Value;
}
}
return null;
}
}
编辑:对不起,我的格式不好,这是我第一次发布堆栈溢出。
有人应该如何告诉你为什么你的系统没有工作..也没有什么'行不通平均???'你也应该使用调试器,并通过您的代码步..如果它是你的机器怎么你不能调试它..?此外..这不是一个代码工厂/测试网站..再次..'Debugger'是你的朋友,如果你知道如何正确使用它 – MethodMan
定义“工作”;你不期望发生了什么,或者你期望发生了什么? –
您遇到的问题是什么?你说*我的系统不工作*但不描述问题。看看[我如何问一个好问题?](http://stackoverflow.com/help/how-to-ask)。很好,你展示的代码不起作用 - 现在,告诉我们它做错了什么,包括导致问题的XML示例。 – dbc