Read large xml file and extract it's data into a form application in C#.Net project -
i want read xml file data , extract information show in form in c#.net vs2008 env. can't read data list in memory, want have .exe file project can run in computer system. think, can't use database saving , retrieving data! please me solve problem!
use system.xml.xmlreader read xml file. forward reader loads bit of xml @ time.
combine iterator method produces ienumerable, such example, myxmldata class representing held in xml file , class forms can work with:
public ienumerable<myxmldata> queryfile(string xmlfile) { using (var reader = xmlreader.create(xmlfile)) { // these variables want read each 'object' in // xml file. var prop1 = string.empty; var prop2 = 0; var prop3 = datetime.today; while (reader.read()) { // here you'll have read xml node @ time. // read, assign appropriate values variables // declared above. if (/* have finished reading item? */) { // once you've completed reading xml representing single // myxmldata object, return using yield return. yield return new myxmldata(prop1, prop2, prop3); } } } }
the value returned method sequence of myxmldata objects each 1 created on demand file read, 1 @ time. reduce memory requirements large xml file.
you can query myxmldata objects using linq functions. example, can emulate paging using take , skip methods.
// third page - 50 objects per page. queryfile(@"x.xml").skip(100).take(50);
Comments
Post a Comment