关于xml load 文件时:The data at the root level is invalid. Line 1, position 1.

来源:互联网 发布:java全局变量命名规则 编辑:程序博客网 时间:2024/06/05 14:47

今天在读取XML时,突然遇到这问题了,

总是提示: 

The data at the root level is invalid. Line 1, position 1.

-XmlDocument doc = new XmlDocument();
-doc.LoadXml(FilePath);

就是有错误,XML也是对的。

--------------------

最后终于找到错误所在了:

XmlDocument 有两个方法:

- Load(string FilePath); // 输入绝对路径,或者相对路径

-LoadXml(string XmlContent);// XmlContent 包含xml元素的串

如:

 XmlDocument doc = new XmlDocument();
    doc.LoadXml("<item><name>wrench</name></item>");
-------------------------------

所以,要分清楚使用。

从文件读入, 使用; 

Load(@"sample.xml");

 

wisdom Guo

2007-11-29