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);
目录
相关文章
|
7天前
|
Java
【ERROR】‘<>‘ operator is not allowed for source level below 1.7
【ERROR】‘<>‘ operator is not allowed for source level below 1.7
7 0
|
关系型数据库 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
1542 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
53 0
|
10月前
|
Java 开发工具 git
解决Error running XXXApplicationCommand line is too long.报错
解决Error running XXXApplicationCommand line is too long.报错
|
8月前
|
人工智能 自然语言处理 语音技术
Invalid prop: type check failed for prop “index“. Expected String with value “5“问题解决
Invalid prop: type check failed for prop “index“. Expected String with value “5“问题解决
65 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'
625 0
【TP5.1】variable type error: array
【TP5.1】variable type error: array
157 0
【TP5.1】variable type error: array
成功解决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