无法在WinXp上写入XML文件

本文关键字:XML 文件 WinXp | 更新日期: 2023-09-27 18:20:43

我的程序中有一个问题:运行Win XP时,不可能在后台工作者的doWork()中写入XML文件;

这是BW:内的代码

try
{
    updateUI(file.FullName, 2);
    writeToXml(file, e.Argument.ToString());
}

xml文件的创建:

XDocument xmlDocVideoList = new XDocument(
                                 new XDeclaration("1.0", "utf-8", "yes"),
                                 new XComment("..."),
                                 new XElement(/*ns+*/"VideoList"));
xmlDocVideoList.Save(saveFileDialog1.FileName);

writeToXml方法:

 public void writeToXml(FileInfo file, string path)
    {
        fileCounterMapped++;
        Video temp = new Video();
        temp.nameFile = file.Name;
        temp.nameVideo = temp.processNameFile(temp.nameFile);
        temp.path = file.Directory.FullName;
        XmlDocument doc = new XmlDocument();
        doc.Load(path);
        XmlNode node = doc.CreateNode(XmlNodeType.Element, "Video", null);
        XmlNode subnodeFN = doc.CreateNode(XmlNodeType.Element, "FileName", null);
        XmlNode subnodeVN = doc.CreateNode(XmlNodeType.Element, "VideoName", null);
        XmlNode subnodePATH = doc.CreateNode(XmlNodeType.Element, "Path", null);
        subnodeFN.InnerText = temp.nameFile;
        subnodeVN.InnerText = temp.nameVideo;
        subnodePATH.InnerText = temp.path;
        node.AppendChild(subnodeFN);
        node.AppendChild(subnodeVN);
        node.AppendChild(subnodePATH);

        doc.DocumentElement.AppendChild(node);
        doc.Save(path);
    }

在我的电脑中,运行Win7是可行的,但在所有带有WinXP的电脑中都不起作用。在所有的计算机中,我都使用Visual Studio 10 Express,并且我有FrameWork 4。

提前感谢!

无法在WinXp上写入XML文件

XDocument对象属于.Net的较新版本,可以尝试只使用XMLDocument。

如果您使用的是.NET 3.0或更低版本,则必须使用XmlDocument,也就是经典的DOM API。。。也许xp不支持这一点,或者你需要更新你的windows。