缺少根元素 [英] Missing root element

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

问题描述

我有以下代码,允许我将数据插入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");
}

推荐答案

错误说实话。每个有效的xml文档都有一个根元素,其他人在其下。可能它在行' xDoc.Save '中给出了这个错误。如果你调试它(启动f5,步骤f10,断点f9)并检查 xDoc.InnerText ,你可以看到错误的位置。
error says the truth. every valid xml document has a root element where others are under it. possibly it gives this error at line 'xDoc.Save'. if you debug it (start f5, step f10, breakpoint f9) and check xDoc.InnerText, you can see where the error is.


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆