读取XML文件的末尾 [英] Reading the end of an XML file

查看:86
本文介绍了读取XML文件的末尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,该程序循环遍历XML文件,每1000条记录输出到另一个文件. Thyis可以正常工作,直到到达XML文件的末尾为止,但失败的原因是我的'root'标签没有关闭-尽管它适用于先前的文件.识别XML文件的末尾似乎有问题,所以有人可以确认如何完成吗?目前,我有一个while循环来执行此操作,其中包含一个for循环以循环浏览记录,即:

while(XmlReader.Read())
{
...

for(int i = 1; i< = 100; i ++)
{
而(在此处读取节点)
{
做这项工作
}
}

关闭XmlReader和XmlWriter
}

这对于开头是很好的方法,直到到达文件结尾为止.是我读取XML文件的方式正确(我也尝试过XmlReader!= null),还是有更好的方法?

非常感谢.
I have a program that cycles through an XML file and outputs to another file every 1000 records. Thyis works fine until the end of the XML file is reached, when it fails saying my 'root' tag is not closed - although it does for the previous files. It seems to be having issues with recognising the end of the XML file, so can someone please confirm how this is done? Currently I have a while loop to do this, with a for loop inside to cycle through the records, ie:

while (XmlReader.Read())
{
...

for (int i = 1; i <= 100; i++)
{
while (reads in a node here)
{
does the work
}
}

Close the XmlReader and XmlWriter
}

This works fine for the beginning, until the end of the file is reached; is my way of reading the XML file correct (I have also tried XmlReader != null), or is there a better way?

Many thanks.

推荐答案

您做得还不错

read()会处理它.

read() takes care of it.

u还可以使用while(!XmlReader.Eof())

u could also use while (!XmlReader.Eof())


这篇关于读取XML文件的末尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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