Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我正在尝试从xml文件Wp8中删除一个节点_Xml_Windows Phone 8 - Fatal编程技术网

我正在尝试从xml文件Wp8中删除一个节点

我正在尝试从xml文件Wp8中删除一个节点,xml,windows-phone-8,Xml,Windows Phone 8,您好,我正在尝试使用ISO存储从xml文件中删除一个元素,节点被删除,但xml变形 代码是: public void deleteFromXML(string appName) { using (IsolatedStorageFile isoStorage = IsolatedStorageFile.GetUserStoreForApplication()) { using (var stream = isoStorage.OpenFile("ISOconfig

您好,我正在尝试使用ISO存储从xml文件中删除一个元素,节点被删除,但xml变形

代码是:

public void deleteFromXML(string appName)
{

    using (IsolatedStorageFile isoStorage = IsolatedStorageFile.GetUserStoreForApplication())
    {
        using (var stream = isoStorage.OpenFile("ISOconfig.xml", FileMode.Open, FileAccess.ReadWrite))
        {
            XDocument xml = XDocument.Load(stream);
            xml.Descendants("ContainerApp")
                    .Where(x => x.Element("AppName").Value.Equals(appName))
                    .Remove();
            // stream.Position = 0;
            // xml.Save(stream);
            stream.Close();
            // Save To ISOconfig.xml File oeration not permited on IsolatedStorageFileStream

            using (IsolatedStorageFileStream newStream = new IsolatedStorageFileStream("ISOconfig.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, isoStorage))
            {
                xml.Save(newStream);
            }
        }
    }
}

所做的更改是在linq查询关闭流并将其保存为:

stream.Close(); //保存到ISOconfig.xml文件 使用(IsolatedStorageFileStream newStream=新的IsolatedStorageFileStream(“ISOconfig.xml”,FileMode.Create,isoStorage)) { Save(newStream);
}

如果您需要添加上下文/代码,请编辑您的问题,不要将其作为答案发布。