winform读取XML报错“未将对象引用设置到对象的实例。”如何解决

winform读取XML报错“未将对象引用设置到对象的实例。”怎么解决
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(@"D:\abc.xml");
            XmlElement xmlRoot = xmlDoc.DocumentElement;
            foreach (XmlNode node in xmlRoot.ChildNodes)
            {
                label1.Text = node["Label"].InnerText;//这行报错未将对象引用设置到对象的实例。
            }

------解决方案--------------------
node["Label"]不存在,没有这个属性,你访问它能行吗
------解决方案--------------------
你是在foreach里写代码,不可能每个节点都叫Label1吧
不是应该用switch判断,什么名赋值给什么变量,这样么
------解决方案--------------------
读取XML数据示例
 //调用公共类中的GetData方法,读取XML文件中的数据
private object GetData(DataTable dt,string sColumnName,string dColumnName,string sValue)
{
DataRow[] rows = dt.Select(sColumnName + "='" + sValue + "'");
if(rows.Length <= 0) return null;
return rows[0][dColumnName];
}//CodeGo.net/
//使用DataTable方法读取XML数据
public static DataTable GetData(string path,string tableName,params XmlParamter[] param)
{
//创建XmlDocument类的实例
            XmlDocument xmldoc = new XmlDocument();
            //调用XmlDocument类中的Load()方法加载XML文件
            xmldoc.Load(path);
            //创建DataTable类型的变量dt
DataTable dt = new DataTable();
///获取根节点
            XmlNode rootNode = xmldoc.SelectSingleNode("/" + tableName + "s");
            //判断节点及其子节点是否为空,为空将返空值
if(rootNode == null) return null;
if(rootNode.ChildNodes.Count == 0) return null;
///创建保存记录的数据列
foreach(XmlAttribute attr in rootNode.ChildNodes[0].Attributes)
{
dt.Columns.Add(new DataColumn(attr.Name,typeof(string)));
}
///创建获取数据节点的XPath
string xmlPath = "/" + tableName + "s/" + tableName;
int operationCount = 0;
StringBuilder operation = new StringBuilder();
foreach(XmlParamter p in param)
{
if(p.Direction == ParameterDirection.Insert

------解决方案--------------------
 p.Direction == ParameterDirection.Update)
{
continue;
}
///创建条件表达式
switch(p.Direction)
{
case ParameterDirection.Equal:
operation.Append("@" + p.Name + "='" + p.Value + "'");
break;
case ParameterDirection.NotEqual:
operation.Append("@" + p.Name + "<>'" + p.Value + "'");
break;
case ParameterDirection.Little:
operation.Append("@" + p.Name + "<'" + p.Value + "'");
break;
case ParameterDirection.Great:
operation.Append("@" + p.Name + ">'" + p.Value + "'");
break;
case ParameterDirection.Like:
operation.Append("contains(@" + p.Name + ",'" + p.Value + "')");
break;
default: break;
}
operationCount++;
operation.Append(" and ");
}
if(operationCount > 0)
{   ///修正XPath
operation.Remove(operation.Length - 5,5);
xmlPath += "[" + operation.ToString() + "]";
}
            //获取XML节点下的所有节点
            XmlNodeList nodeList = xmldoc.SelectNodes(xmlPath);
///遍历所有节点,并添加节点的数据
foreach(XmlNode node in nodeList)
{
DataRow row = dt.NewRow();
foreach(DataColumn column in dt.Columns)
{   ///读取每一个属性
row[column.ColumnName] = node.Attributes[column.ColumnName].Value;
}
dt.Rows.Add(row);
}
return dt;
}

------解决方案--------------------
空异常。node["Label"] 值是null