public void addVmHost(vmHost host) { XmlNode node; XmlNode root = doc.DocumentElement; node = root.SelectSingleNode("//vmhost[@id='" + host.id + "']"); if (node == null) { XmlElement vmNode = doc.CreateElement("vmhost"); vmNode.InnerText = host.path; //attr:name XmlAttribute nameAttr = doc.CreateAttribute("name"); nameAttr.InnerText = host.name; vmNode.Attributes.Append(nameAttr); //attr:id XmlAttribute idAttr = doc.CreateAttribute("id"); idAttr.InnerText = host.id; vmNode.Attributes.Append(idAttr); root.AppendChild(vmNode); doc.Save(vmFilePath); } else { MessageBox.Show(host.id + "已存在"); } }
public void editVmHost(vmHost host) { XmlNode node; XmlNode root = doc.DocumentElement; node = root.SelectSingleNode("//vmhost[@id='" + host.id + "']"); if (node == null) { MessageBox.Show(host.id + "不存在"); } else { node.InnerText = host.path; node.Attributes["name"].InnerText = host.name; doc.Save(vmFilePath); } }
public List <vmHost> getVmHostList() { XmlNodeList nodeList; XmlNode root = doc.DocumentElement; nodeList = root.SelectNodes("//vmhost"); List <vmHost> list = new List <vmHost>(); foreach (XmlNode node in nodeList) { vmHost host = new vmHost(); host.id = node.Attributes["id"].InnerText; host.name = node.Attributes["name"].InnerText; host.path = node.InnerText; list.Add(host); //MessageBox.Show(host.name); } return(list); }