public void DeleteXml(XDocument document, string temp1) { foreach (XElement AllElements in document.Element("teams").Element("team").Elements("player")) { if (AllElements.Attribute("name").Value == temp1) { AllElements.Remove(); } else if (AllElements.Element("weight").Value == temp1) { AllElements.Remove(); } else if (AllElements.Element("height").Value == temp1) { AllElements.Remove(); } else if (AllElements.Element("wage").Value == temp1) { AllElements.Remove(); } } document.Save("teams.xml"); }