私はWindows Phone 7アプリを作成しています。隔離されたストレージの中にあるxmlファイルの値を変更することに少し問題があります。 私の方法はここにある:隔離されたストレージに保存されたxmlファイルの値を変更するにはどうすればよいですか?
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);
}
}
}
}
そして分離ストレージ内の私のxmlファイルは次のようになります。私はこのラインからとNullReferenceExceptionを取得
<?xml version="1.0" encoding="utf-8"?>
<items>
<item id="0" title="Milk" image="a.png" lastbought="6" lastingtime="6" />
<item id="1" title="Cheese" image="b.png" lastbought="2" lastingtime="20" />
<item id="2" title="Bread" image="c.png" lastbought="3" lastingtime="8" />
</items>
:
xml.Root.Attribute(itemAttribute).SetValue(value);
任意のアイデアをどのように私はそれをする必要がありますか? 乾杯。
うん、それはうまくいくようです。私はそこにいた脳の凍結がどんなものか不思議です。ありがとう。 – Baburo