读取xml出错
这是XML文件<?xml version="1.0" encoding="utf-8"?>
<company>
<department name="产品设计部">
<team>测试小组</team>
</department>
<department name="产品开发部">
<team>开发小组</team>
</department>
</company>
下面是我的读取代码 我将那些值加到treeview控件中
测试小组是产品设计部下的子节点
XmlDocument xml = new XmlDocument();
xml.Load("Company.xml");
XmlNode xmlnode = xml.DocumentElement;
foreach (XmlNode node in xmlnode.ChildNodes)
{
TreeNode nodes = new TreeNode();
nodes.Text = node.Attributes["name"].Value.ToString();
this.treeView1.Nodes.Add(nodes);
foreach (XmlNode no in node.ChildNodes)
{
TreeNode n = new TreeNode();
n.Text = no["team"].InnerText;
nodes.Nodes.Add(n);
}
}
//n.Text = no["team"].InnerText; 这一句一直报错 愚钝不知道哪里有问题 求解!