我在隔离存储中有一个XML文件,我需要编辑该文件并删除所有出现的"时间"文件中的节点。该文件需要更新。
这是在隔离存储中打开XML文件的代码部分:
using (IsolatedStorageFileStream doc = localStorage.OpenFile(xmlFile, FileMode.Open))
{
}
我试图使用XDocument删除所有" Time"节点,但这似乎没有用,所以我只需要一种从" doc"中删除节点的方法。
此代码已添加,它将新XML添加到文件中,但是当我在本地存储中查看文件时它是空的?
using (IsolatedStorageFileStream doc = localStorage.OpenFile(xmlFile, FileMode.Open))
{
System.Xml.Linq.XDocument test = System.Xml.Linq.XDocument.Load(doc);
test.Declaration.Version = "1.0";
test.Declaration.Encoding = "utf-16";
test.Declaration.Standalone = "yes";
test.Descendants("Time").Remove();
doc.Position = 0;
test.Save(doc);
XmlWriter writer = XmlWriter.Create(doc);
if (location.GetType() == typeof(PortableBusinessObjects.Shape))
_xmlShapeSerializer.Serialize(writer, location);
else if (location.GetType() == typeof(PortableBusinessObjects.Point))
_xmlPointSerializer.Serialize(writer, location);
doc.Flush();
doc.Close();
}
答案 0 :(得分:0)
修改XDocument后,是否将其保存回流(方法Save()
)?因为否则,我认为不会发生这种情况。