天天看點

判斷已有節點是否存在 XML

 string TaskID = listViewtask1.SelectedItems[0].Tag.ToString();

XmlDocument xmldoc = new XmlDocument();

xmldoc.Load("Task.xml");

XmlNode element = xmldoc.ChildNodes[1];

if (element != null)

{

for (int n = 0; n < element.ChildNodes.Count; n++)

{

XmlNode xmlnode = element.ChildNodes[n];

XmlAttribute attribute = xmlnode.Attributes["TaskID"];

if (attribute.Value.ToLower() == TaskID)

{

MessageBox.Show("任務已經存在!");

return;

}

}

}