0
我正在使用.net資源使用LINQ to XML。我想編輯一些資源,所以我這個編碼:在.net中使用LINQ to XML保存資源文件的更改
Public Shared Sub AddTranslation(ByVal filename As String, ByVal name As String, ByVal value As String)
Dim items = From translation In XElement.Load(filename).Elements("data") Where translation.Attribute("name").Value = name
If items.Count = 0 Then 'item doesn't exist => add new item
XElement.Load(filename).Element("translations").Add(New XElement("data", New XAttribute("name", name), New XElement("value", value)))
Else
items(0).Element("value").Value = value
XElement.Load(filename).Save(filename)
End If
End Sub
這似乎是工作,甚至當我調試VisualStudio中說,該文件改變了,但實際上並非如此。我認爲問題出在Save()動作中,但我不知道其他方式來保存它... 任何想法?
在此先感謝,
Alf。
是的,像這樣,謝謝你! – alfizqu 2011-05-07 09:55:33