Click here to Skip to main content
11,410,118 members (61,789 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# XML Data
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>

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
Posted 27-Oct-12 15:07pm
Comments
John_Black at 27-Oct-12 22:29pm
   
Something I have noticed is that my application is significantly quicker when compiled.

Reading the specific xml file only seems slow when running the app within Visual Studio Express either in debug or release mode.
Skywithin at 31-Oct-12 4:34am
   
What are you using to read XML? Is file located locally? Try System.Xml.Linq.XElement.Load()
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try specifying XmlReadMode, this would increase performance.

myDS.ReadXml("C:\\Test\\input.xml", XmlReadMode.ReadSchema);
  Permalink  
Comments
John_Black at 27-Oct-12 22:22pm
   
Thanks for your quick response, however your suggestion made no change in the speed of the ReadXML command unfortunately.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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();

More details and source of the above code is MSDN at http://msdn.microsoft.com/en-us/library/fx29c3yd.aspx[^]

Hope that helps

- Milind
  Permalink  
Comments
John_Black at 28-Oct-12 13:58pm
   
Hi Milind, thanks for response.

However I have already tried that without success.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 169
1 OriginalGriff 110
2 Maciej Los 68
3 BillWoodruff 60
4 Philippe Mori 60
0 Sergey Alexandrovich Kryukov 8,755
1 OriginalGriff 6,915
2 Maciej Los 3,390
3 Abhinav S 3,248
4 Peter Leow 3,059


Advertise | Privacy | Mobile
Web03 | 2.8.150414.5 | Last Updated 28 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100