Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 26th, 2012  |  syntax: None  |  size: 1.85 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to edit XML file in Windows Phone 7.1 application
  2. public void AddSwimGoal(SwimGoal SG)    
  3.     {
  4.         string FileName = "Data/SwimGoals.xml";
  5.         XDocument Doc = new XDocument();
  6.         Doc = XDocument.Load(@FileName);
  7.  
  8.         XElement Root = Doc.Root;
  9.         XElement NewSG = new XElement("SwimGoal");
  10.         XAttribute Dist = new XAttribute("Distance", SG.Distance);
  11.         XAttribute MaxTD = new XAttribute("MaxTrainingDistance", SG.MaxTrainingDistance);
  12.         XAttribute ID = new XAttribute("ID", SG.ID);
  13.         XAttribute Name = new XAttribute("Name", SG.Name);
  14.         XAttribute StartDate = new XAttribute("StartDate", SG.StartDate);
  15.         XAttribute EndDate = new XAttribute("EndDate", SG.EndDate);
  16.         XAttribute DesiredTime = new XAttribute("DesiredTime", SG.Desiredtime);
  17.         XAttribute Stroke = new XAttribute("Stroke", SG.Stroke);
  18.         NewSG.Add(Dist, MaxTD, ID, Name, StartDate, EndDate, DesiredTime, Stroke);
  19.         Root.Add(NewSG);
  20.         XmlWriter Wr = Doc.CreateWriter();
  21.         Doc.Save(Wr);
  22.     }
  23.        
  24. private void saveXML()
  25.                 {
  26.                     using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
  27.                     {
  28.                         IsolatedStorageFileStream stream = store.OpenFile("myapp.Xml", FileMode.Create, FileAccess.Write);
  29.                         _xdoc.Save(stream);
  30.                         stream.Dispose();
  31.                     }
  32.                 }
  33.        
  34. _xdoc = new XDocument(
  35.                                     new XComment("Created " + DateTime.Now.ToLongTimeString()),
  36.                                     new XElement("a",
  37.                                     new XElement("b",
  38.                                     new XElement("c", this.tb_vehicleName.Text.ToString(), new XAttribute("id", 123)),
  39.                                     new XElement("d", ""))));