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

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

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


C#, 读取xml文件中节点数量


int nodeCount = 0;
                        XmlDocument doc = new XmlDocument();
                        doc.Load(file.FullName);
                        //获得根节点
                        XmlNode rootNode = doc.DocumentElement;
                        //在根节点中寻找节点
                        foreach (XmlNode node in rootNode.ChildNodes)
                        {
                            //找到对应的节点
                            if (node.Name == "url")
                            {
                                nodeCount = nodeCount + 1;
                            }
                        }


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


总是提示:


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


-XmlDocument doc = new XmlDocument();


-doc.LoadXml(FilePath);


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


报错就改成:


doc.Load(file.FullName);
目录
相关文章
|
关系型数据库 MySQL 数据库
MySQL新增字段报错:ERROR 1118 -- Row size too large. The maximum row size for the used table type
MySQL新增字段报错:ERROR 1118 -- Row size too large. The maximum row size for the used table type
1512 0
|
1月前
|
存储
tracker_query_storage fail, error no: 28, error info: No space left on device
tracker_query_storage fail, error no: 28, error info: No space left on device
45 0
|
1月前
|
Perl
报错:error Parsing error: x-invalid-end-tag
报错:error Parsing error: x-invalid-end-tag
|
10月前
|
Java 开发工具 git
解决Error running XXXApplicationCommand line is too long.报错
解决Error running XXXApplicationCommand line is too long.报错
|
10月前
|
JavaScript
Error Unknown option ‘--inline‘
Error Unknown option ‘--inline‘
262 0
成功解决absl.flags._exceptions.UnrecognizedFlagError: Unknown command line flag 'data_format'
成功解决absl.flags._exceptions.UnrecognizedFlagError: Unknown command line flag 'data_format'
|
程序员 算法框架/工具 Caffe
解决办法:error: 'size_t' does not name a type、unknown type name 'size_t'
解决办法:error: 'size_t' does not name a type、unknown type name 'size_t'
615 0
成功解决ParserError: Error tokenizing data. C error: Expected 2 fields in line 53, saw 3
成功解决ParserError: Error tokenizing data. C error: Expected 2 fields in line 53, saw 3
|
Web App开发 Java 关系型数据库
Data truncation: Data too long for column 'xxx' at row 1
Data truncation: Data too long for column 'xxx' at row 1 完整的错误内容可能是下面这样的: p.p1 {margin: 0.0px 0.0px 0.
2091 0

热门文章

最新文章