public void InsertWords(OjWord ojWord) { try { XmlDocument = XDocument.Load(filenameXmlGameLearnNewWords); XElement Word = new XElement("OjWord", new XAttribute("ID", ojWord.ID1), new XElement("Word", ojWord.Word1), new XElement("FileNameWord", ojWord.FileNameword1), new XElement("LocationStress", ojWord.LocationStress1.ToString()), new XElement("Purport", ojWord.Purport1), new XElement("Topic", ojWord.Topic1)); XmlDocument.Root.Add(Word); XmlDocument.Save(filenameXmlGameLearnNewWords); } catch (Exception) { } }
public void UpdateWord(string ID, OjWord newojWord) { try { XmlDocument = XDocument.Load(filenameXmlGameLearnNewWords); IEnumerable <XElement> oldElement = from q in XmlDocument.Element("Words").Elements("OjWord") where (q.Attribute("ID").Value.ToString() == ID) select q; foreach (XElement item in oldElement) { item.SetElementValue("Word", newojWord.Word1); item.SetElementValue("FileNameWord", newojWord.FileNameword1); item.SetElementValue("LocationStress", newojWord.LocationStress1); item.SetElementValue("Purport", newojWord.Purport1); item.SetElementValue("Topic", newojWord.Topic1); } XmlDocument.Save(filenameXmlGameLearnNewWords); } catch (Exception) {} }