读取XML文件“有时"很慢 [英] Reading XML files is 'sometimes' slow
问题描述
现在,在开始解释问题之前,我已经阅读了几篇有关读取大小超过1 GB的XML文件的问题的文章.那不是我的问题,所以我相信.
我有两个XML文件,两个文件的大小均为4MB,文件A的元素大约为10000,文件B的元素为1500.具体的元素大小不同.
现在非常奇怪的是,文件A只需使用DataSet.ReadXML读取一秒钟的时间,而文件B则需要两分钟以上的时间!
有人以前发现过这样的东西吗?我缺少明显的东西吗?
XML文件的结构因此是
Hi,
Now before I start explaining my issue, I have read a few articles about issues reading XML files over a GB in size. That is not my issue, or so I believe.
I have two XML files, both about 4MB in size, file A with roughly 10000 elements, file B with 1500. The specific elements are differing in size.
Now quite bizarrely file A takes a fraction of a second to be read using DataSet.ReadXML and yet file B takes over two minutes!
Any one found anything like this before? Am I missing something obvious?
The structure of the XML files is thus
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
Schema definition here
<element>
<id>1</id>
<datafield1>xxxx</datafield1>
<datafield2>xxxx</datafield2>
....
</element>
<element>
....
</NewDataSet>
如果我对元素"一词的使用不正确,我深表歉意,a,我是一位自学成才的C#编码器.
任何帮助将不胜感激
干杯
I apologise if my use of the term ''element'' is incorrect, alas I am a self-taught C# coder.
Any help is greatly appreciated
Cheers
推荐答案
尝试指定XmlReadMode,这样可以提高性能.
Try specifying XmlReadMode, this would increase performance.
myDS.ReadXml("C:\\Test\\input.xml", XmlReadMode.ReadSchema);
既然您说的是两个文件都大约4 MB,但是一个文件有10000个元素,而第二个文件有1500个元素,因此我认为结构是不同的,这可能导致读取多个表.
您可能想在调用ReadXml方法之前尝试调用BeginLoadData.
Hi,
Since you are saying both the files are around 4 MB, but one has 10000 elements whereas second has 1500 elements, I assume, the structure is different which might be causing multiple table reading.
You may like to try calling BeginLoadData before calling ReadXml method.
foreach (DataTable dataTable in dataSet.Tables)
dataTable.BeginLoadData();
dataSet.ReadXml("file.xml");
foreach (DataTable dataTable in dataSet.Tables)
dataTable.EndLoadData();
上述代码的更多详细信息和来源是MSDN,网址为 http://msdn.microsoft.com/en-us /library/fx29c3yd.aspx [ ^ ]
希望对您有帮助
-Milind
More details and source of the above code is MSDN at http://msdn.microsoft.com/en-us/library/fx29c3yd.aspx[^]
Hope that helps
- Milind
这篇关于读取XML文件“有时"很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!