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);
目录
相关文章
|
3月前
|
Docker 容器
ADD failed: file not found in build context or excluded by .dockerignore: stat irap_rule_center: fil
ADD failed: file not found in build context or excluded by .dockerignore: stat irap_rule_center: fil
|
7月前
|
存储
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
171 0
|
Java 开发工具 git
解决Error running XXXApplicationCommand line is too long.报错
解决Error running XXXApplicationCommand line is too long.报错
成功解决absl.flags._exceptions.UnrecognizedFlagError: Unknown command line flag 'data_format'
成功解决absl.flags._exceptions.UnrecognizedFlagError: Unknown command line flag 'data_format'
|
XML 数据格式
XML问题: The processing instruction target matching "[xX][mM][lL]" is not allowed
XML问题: The processing instruction target matching "[xX][mM][lL]" is not allowed
211 0
|
Linux
编译OpenJDK8:error: control reaches end of non-void function [-Werror=return-type]
编译OpenJDK8:error: control reaches end of non-void function [-Werror=return-type]
188 0
|
程序员 算法框架/工具 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'
747 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
|
Java 应用服务中间件 Android开发