title: How do I modify a value in xml file stored inside isolated storage?
body: <p>I'm creating a windows phone 7 app and I'm having a bit of a trouble with changing values in my xml-file, which is located inside isolated storage.
  My method is here:</p>
  
  <pre><code>public void updateItemValueToIsoStorage(string id, 
                                          string itemAttribute, 
                                          string value)
  {
      using (var isoStorage = IsolatedStorageFile.GetUserStoreForApplication())
      {
          using (var stream = isoStorage.OpenFile(
                             "items.xml", FileMode.Open, FileAccess.ReadWrite))
          {
              XDocument xml = XDocument.Load(stream, LoadOptions.None);
              //According to given parameters, 
              //set the correct attribute to correct value.
              var data = from c in xml.Descendants("item")
                         where c.Attribute("id").Value == id
                         select c;
              foreach (Object i in data) 
              {
  
                  xml.Root.Attribute(itemAttribute).SetValue(value);
  
              }                
          }
      }
  }
  </code></pre>
  
  <p>And my xml-file inside isolated storage looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;items&gt;
  &lt;item id="0" title="Milk" image="a.png" lastbought="6" lastingtime="6" /&gt;
  &lt;item id="1" title="Cheese" image="b.png" lastbought="2" lastingtime="20" /&gt;
  &lt;item id="2" title="Bread" image="c.png" lastbought="3" lastingtime="8" /&gt;
  &lt;/items&gt;
  </code></pre>
  
  <p>I get a NullReferenceException from this line:</p>
  
  <pre><code>xml.Root.Attribute(itemAttribute).SetValue(value);
  </code></pre>
  
  <p>Any ideas how I should do it then?
  Cheers.</p>