Note that there are some explanatory texts on larger screens.

plurals
  1. POFastest way to parse XML files in C#?
    text
    copied!<p>I have to load many XML files from internet. But for testing with better speed i downloaded all of them (more than 500 files) of the following format.</p> <pre><code>&lt;player-profile&gt; &lt;personal-information&gt; &lt;id&gt;36&lt;/id&gt; &lt;fullname&gt;Adam Gilchrist&lt;/fullname&gt; &lt;majorteam&gt;Australia&lt;/majorteam&gt; &lt;nickname&gt;Gilchrist&lt;/nickname&gt; &lt;shortName&gt;A Gilchrist&lt;/shortName&gt; &lt;dateofbirth&gt;Nov 14, 1971&lt;/dateofbirth&gt; &lt;battingstyle&gt;Left-hand bat&lt;/battingstyle&gt; &lt;bowlingstyle&gt;Right-arm offbreak&lt;/bowlingstyle&gt; &lt;role&gt;Wicket-Keeper&lt;/role&gt; &lt;teams-played-for&gt;Western Australia, New South Wales, ICC World XI, Deccan Chargers, Australia&lt;/teams-played-for&gt; &lt;iplteam&gt;Deccan Chargers&lt;/iplteam&gt; &lt;/personal-information&gt; &lt;batting-statistics&gt; &lt;odi-stats&gt; &lt;matchtype&gt;ODI&lt;/matchtype&gt; &lt;matches&gt;287&lt;/matches&gt; &lt;innings&gt;279&lt;/innings&gt; &lt;notouts&gt;11&lt;/notouts&gt; &lt;runsscored&gt;9619&lt;/runsscored&gt; &lt;highestscore&gt;172&lt;/highestscore&gt; &lt;ballstaken&gt;9922&lt;/ballstaken&gt; &lt;sixes&gt;149&lt;/sixes&gt; &lt;fours&gt;1000+&lt;/fours&gt; &lt;ducks&gt;0&lt;/ducks&gt; &lt;fifties&gt;55&lt;/fifties&gt; &lt;catches&gt;417&lt;/catches&gt; &lt;stumpings&gt;55&lt;/stumpings&gt; &lt;hundreds&gt;16&lt;/hundreds&gt; &lt;strikerate&gt;96.95&lt;/strikerate&gt; &lt;average&gt;35.89&lt;/average&gt; &lt;/odi-stats&gt; &lt;test-stats&gt; . . . &lt;/test-stats&gt; &lt;t20-stats&gt; . . . &lt;/t20-stats&gt; &lt;ipl-stats&gt; . . . &lt;/ipl-stats&gt; &lt;/batting-statistics&gt; &lt;bowling-statistics&gt; &lt;odi-stats&gt; &lt;matchtype&gt;ODI&lt;/matchtype&gt; &lt;matches&gt;378&lt;/matches&gt; &lt;ballsbowled&gt;58&lt;/ballsbowled&gt; &lt;runsgiven&gt;64&lt;/runsgiven&gt; &lt;wickets&gt;3&lt;/wickets&gt; &lt;fourwicket&gt;0&lt;/fourwicket&gt; &lt;fivewicket&gt;0&lt;/fivewicket&gt; &lt;strikerate&gt;19.33&lt;/strikerate&gt; &lt;economyrate&gt;6.62&lt;/economyrate&gt; &lt;average&gt;21.33&lt;/average&gt; &lt;/odi-stats&gt; &lt;test-stats&gt; . . . &lt;/test-stats&gt; &lt;t20-stats&gt; . . . &lt;/t20-stats&gt; &lt;ipl-stats&gt; . . . &lt;/ipl-stats&gt; &lt;/bowling-statistics&gt; &lt;/player-profile&gt; </code></pre> <p>I am using </p> <pre><code>XmlNodeList list = _document.SelectNodes("/player-profile/batting-statistics/odi-stats"); </code></pre> <p>And then loop this list with <code>foreach</code> as </p> <pre><code>foreach (XmlNode stats in list) { _btMatchType = GetInnerString(stats, "matchtype"); //it returns null string if node not availible . . . . _btAvg = Convert.ToDouble(stats["average"].InnerText); } </code></pre> <p>Even i am loading all files offline, parsing is very slow Is there any good faster way to parse them? Or is it problem with SQL? I am saving all extracted data from XML to database using DataSets, TableAdapters with insert command.</p> <p><strong>EDIT:</strong> Now for using XmlReader please give some code of XmlReader for above document. for now, i have done this </p> <pre><code>void Load(string url) { _reader = XmlReader.Create(url); while (_reader.Read()) { } } </code></pre> <p>Availible Methods for XmlReader are confusing. What i need is to get batting and bowling stats completly, batting and bowling stats are different, while odi,t2o,ipl etc are same inside bowling and batting.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload