
Untitled
By: a guest on
Apr 26th, 2012 | syntax:
None | size: 1.85 KB | hits: 21 | expires: Never
How to edit XML file in Windows Phone 7.1 application
public void AddSwimGoal(SwimGoal SG)
{
string FileName = "Data/SwimGoals.xml";
XDocument Doc = new XDocument();
Doc = XDocument.Load(@FileName);
XElement Root = Doc.Root;
XElement NewSG = new XElement("SwimGoal");
XAttribute Dist = new XAttribute("Distance", SG.Distance);
XAttribute MaxTD = new XAttribute("MaxTrainingDistance", SG.MaxTrainingDistance);
XAttribute ID = new XAttribute("ID", SG.ID);
XAttribute Name = new XAttribute("Name", SG.Name);
XAttribute StartDate = new XAttribute("StartDate", SG.StartDate);
XAttribute EndDate = new XAttribute("EndDate", SG.EndDate);
XAttribute DesiredTime = new XAttribute("DesiredTime", SG.Desiredtime);
XAttribute Stroke = new XAttribute("Stroke", SG.Stroke);
NewSG.Add(Dist, MaxTD, ID, Name, StartDate, EndDate, DesiredTime, Stroke);
Root.Add(NewSG);
XmlWriter Wr = Doc.CreateWriter();
Doc.Save(Wr);
}
private void saveXML()
{
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
IsolatedStorageFileStream stream = store.OpenFile("myapp.Xml", FileMode.Create, FileAccess.Write);
_xdoc.Save(stream);
stream.Dispose();
}
}
_xdoc = new XDocument(
new XComment("Created " + DateTime.Now.ToLongTimeString()),
new XElement("a",
new XElement("b",
new XElement("c", this.tb_vehicleName.Text.ToString(), new XAttribute("id", 123)),
new XElement("d", ""))));