Ken Nguyen

Ken Nguyen

  • NA
  • 11
  • 16.5k

Save xml file in windows phone 7

Nov 1 2011 4:29 AM
How can I save xml file (code) ?
Hello everybody. I can read the xml file, but I can't save xml file :
Sample :
  public class Subject
  {
  public int Id
  {
  get;
  set;
  }
  public Subject()
  {}
  public string Name
  {
  get;
  set;
  }
  public string Number
  {
  get;
  set;
  }
  }
  public class Student
  {
  public string Id
  {
  get;
  set;
  }
  public Student()
  {}
  public string Name
  {
  get;
  set;
  }
 
  public string IconURI
  {
  get;
  set;
  }
  public List<Subject> Subjects
  {
  get;
  set;
  }
  }
  public partial class MainPage : PhoneApplicationPage
  {
  public MainPage()
  {
  InitializeComponent();
  }
  public List<Student> Students
  {
  get;
  set;
  }
  }
  private void LoadXML()
  {
  Uri uri = new Uri("/DemoWP7;component/Save.xml", UriKind.Relative);
  StreamResourceInfo xml = App.GetResourceStream(uri);
  XDocument doc = XDocument.Load(xml.Stream);
  XElement menu = doc.Descendants("menu").First();
  Students = (from student in menu.Descendants("student")
  select new Student()
  {
  Id = student.Attribute("id").Value,
  Name = student.Attribute("name").Value,
  IconURI = student.Attribute("icon").Value,
  Subjects = (from subject in student.Descendants("subject")
  select new Subject()
  {
  Name = subject.Attribute("name").Value,
  Number = subject.Attribute("number").Value,
  }).ToList<Subject>()
  }).ToList<Student>();
  }
I need save the file .xml same this, after that LoadXML()
  <?xml version="1.0" encoding="utf-8" ?>
  <menu>
  <student id="group1" name="Team A" icon="Images/Team-A.png">
  <subject name="Math"
  number="72">
  </subject>
  <subject name="Art"
  number="85">
  </subject>
  </student>
  <student id="group2" name="Team D" icon="Images/Team-D.png">
  <subject name="History"
  number="69">
  </subject>
  </student>
  </menu>
How can I save xml file (code) ?





Answers (1)