缺少根元素

扫码查看
本文介绍了缺少根元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,允许我将数据插入xml。如果我将第二个或以上的数据插入xml文件,这是可以的,并且工作正常。但是,当我想插入第一个数据(表明xml文件完全为空)时,它会提示错误,如标题所示。任何想法?



Hi, i have the following codes which allow me to insert data into xml. If i am inserting a second or above data into the xml file it is ok and works fine. But when i wanna insert a first data(which indicated that the xml file is totally empty), it will prompt an error as the title said. Any ideas?

if (xRoot != null)
{
    xDoc.Load("C:\\Users\\Visual\\Documents\\Visual Studio 2010\\Projects\\FTP Setup\\FTP Setup\\bin\\Debug\\ftpSetup.xml");

    XmlNode importNode = xDoc.ImportNode(xNode1, true);
    XmlNode parentNode = xDoc.SelectSingleNode("FTP_Information");
    parentNode.InsertBefore(xNode1, parentNode.FirstChild);
    xDoc.Save("C:\\Users\\Visual\\Documents\\Visual Studio 2010\\Projects\\FTP Setup\\FTP Setup\\bin\\Debug\\ftpSetup.xml");
    MessageBox.Show("Successful");
}

推荐答案


这篇关于缺少根元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 20:14
查看更多