I have one xml file name "person.xml" with structure like this
<?xml version="1.0" encoding="utf-8" ?>
<people>
<person id="1" name="" age="" />
<person id="2" name="" age="" />
<person id="3" name="" age="" />
</people>
I want to update the person id 1 over its name and age; my code to do that is like this
using(IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
filename = "person.xml";
if(storage.FileExists(filename))
{
using(IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream(filename,FileMode.Open,storage))
{
XDocument doc = XDocument.Load("person.xml");
foreach (var item in (from item in doc.Descendants("person")
where item.Attribute("id").Equals("1")
select item).ToList())
{
item.Attribute("name").SetValue("Hello");
item.Attribute("age").SetValue("24");
}
doc.Save(isoStream);
}
}
}
However, after I run the application and check the value in person.xml, I saw the value on person id 1 has never been updated. As I debuge the application during runtime, the breakpoint skipped at line "if(storage.FileExists(filename))" as though the file person.xml does not exist but I did create it and see it in the solution explorer.
Last, please forgive me I know that my question might be duplicated as one I followed on updating an existing xml file in Windows Phone and the other sources on web, yet following them, I've still never abled to solve it by own problem.