XML Reading / Saving RRS feed

  • Question

  • Hello all,

    I have been struggling with this one issue for too long, and I know I must be missing something fairly simple. I have been searching and can’t seem to find the solution…

    I have an XML file that I am loading in the app in the solutions window “Data/quotes.xml” (it has a build action of content). I am able to read, search, and display everything fine. The issue is that I have an element in the XML ‘favorite’ and by default it is a 0 (zero). I have a button that allows the user to click favorite. I can search for and find the record but all attempts to save the element value with a 1 (one) fails.

    It looks like the issue is that I need a stream to use xmlDoc.Save(); and I can’t seem to get a IsolatedStorageFileStream to work I am guessing because this file is not in Isolated Storage. I have tried many samples of code posted in threads and blogs, but the save doesn’t work or it throws an exception.

    The goal is something like:
    var results = (from q in quote_xml.Descendants("quote") where int.Parse(q.Element("quote_id").Value) == int.Parse(this_quote_id) select q);

    if (results.Count() > 0)
    foreach (XElement xe in results)
    xe.SetElementValue("favorite", "1");

    Thank you in advance for any help.


    Friday, November 26, 2010 7:30 PM

All replies

  • You'll have to create a separate file for saving in IsolatedStorage.
    Friday, November 26, 2010 7:58 PM
  • Thanks for the reply -- are you saying that files in the project, but not in Isolated Storage can't be updated, even if they belong to the app? Scott
    Friday, November 26, 2010 9:45 PM
  • Sorry to butt in. Precisely. IsolatedStorage is the only persistent medium on the device, I'm afraid.
    Friday, November 26, 2010 9:57 PM
  • Thanks for the clarification -- dealing with data on the phone device seems to be challenging... I hope this gets easier as i get more familiar with the framework / devices.

    I hope this saved somebody else some time :-)

    Thanks again for your help.

    Friday, November 26, 2010 10:10 PM