NullReferenceException when changing XML element attribute value

djhowarth187

New Member
this is my method to change XML element attribute value:\[code\]using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()){ XDocument xml = null; using (IsolatedStorageFileStream isoFileStream = myIsolatedStorage.OpenFile("Stats_file.xml", FileMode.Open, FileAccess.Read)) { xml = XDocument.Load(isoFileStream, LoadOptions.None); xml.Element("statrecords").SetElementValue("value", "2"); //nullreferenceexception } using (IsolatedStorageFileStream isoFileStream = myIsolatedStorage.OpenFile("Stats_file.xml", FileMode.Truncate, FileAccess.Write)) { xml.Save(isoFileStream, SaveOptions.None); }}\[/code\]In 7th line i have NullReferenceException. Do you know how to change value without error?This is my XML file:\[code\]<?xml version='1.0' encoding='utf-8' ?><stats> <statmoney index='1' value='http://stackoverflow.com/questions/14565064/0' alt='all money' /> <statrecords index='2' value='http://stackoverflow.com/questions/14565064/0' alt='all completed records' /></stats>\[/code\]
 
Back
Top