在c#中,如何循环load多个XmlDocument?

来源:百度知道 编辑:UC知道 时间:2024/06/01 19:38:27
在一个xml文件中,包含多个xml数据库文件的文件名,是我要提取的对象。

我已经提取除了这些文件名,在string[] allF中。我在代码中循环的提取每个文件的内容,代码如下:

for (int i = 1; i < allF.Length - 1; i++)
{
XmlDocument fileDoc = new XmlDocument();
XmlTextReader r = new XmlTextReader(indexFile);
fileDoc.Load(r);

//下面是其他操作
XmlNode docRoot = fileDoc.DocumentElement;
……
}

第一次循环操作成功。
第二次循环出现错误:未处理的异常,System.Xml.XmlException: 引用了未声明的实体“Cx1F”……

我换过用XmlTextReader,也出现同样的问题。
而网上我没有找到怎样循环读取XMl文档的例子。

请问这个问题出错在哪?难道不能循环使用load的功能么?
放错代码了:

for (int i = 1; i < allF.Length - 1; i++)
{
XmlDocument fileDoc = new XmlDocument();
fileDoc.Load(allF[i]);

//下面是其他操作
XmlNode docRoot = fileDoc.DocumentElement;
……
}

错误就出在fileDoc.Load(allF[i])这一行。

载入对象错误:你的xml文件是否正确?
/////////////////////////////////最新更新

可以这样理解:你的一个string[]类型的数组存储的是xml文件地址,现在你便利这个数组,读取每个xml文件地址的内容?

实例如下:

using System;
using System.Xml;
class Test
{
static void Main()
{
string[] strFileUrlList = new string[] { "C:\\a.xml", "C:\\b.xml", "C:\\c.xml" };
foreach (string str in strFileUrlList)
{
XmlDocument document = new XmlDocument();
document.Load(str);
Console.WriteLine(document.InnerXml);
}
for (int index = 0; index < strFileUrlList.Length; index++)
{

}
Console.ReadKey();
}
}