title: How to write a variable to an XML file?
body: <p>I have a question. How do you write a variable to an XML file using Linq to XML? I have it set up so that the variable gets put in a public variable</p>
  
  <pre><code>     public string name;
       public string age;
  </code></pre>
  
  <p>The value that is put into these is</p>
  
  <pre><code>     this.name = characterTextBox.Text;
       this.age = characterageTextBox.Text;
  </code></pre>
  
  <p>Now I have created a class that handles the placement of these variables into the XML file, but everytime I attempt to retrieve the variable from the public string, It always comes out as null; even though I tested to see if it was null when I saved it to the public variable.
  Here is the saving code</p>
  
  <pre><code>    Form1 f = new Form1();
          String name = f.name;
          String age = f.age;
  
  
          var doc = XDocument.Load(XMLFILE.xml);
  
  
          var newElement = new XElement("player", name,
              new XElement("age", age));
  
          doc.Element("players").Add(newElement);
  
  
          doc.Save(XMLFILE.xml);
  </code></pre>
  
  <p>If anyone could help, that would be very much appreciated.</p>
  
  <p>Thanks.</p>