c# - How to write Parsed and extracted data in XML before SqlServer Database insertion -



c# - How to write Parsed and extracted data in XML before SqlServer Database insertion -

i have set of parser component functions in web application capable of parsing , extracting info next flat files

1) tabdelimitedfile.fileextenstion parsed , extracted using this reference!!

2) file.xml files info parsed , extracted using linqtoxml

3) excel.xlsx files info parsed , extracted using linqtoexcel

upon parsing , extraction of datasets inserting them sql server database using linqtosql classes , dbmldatacontext.

my requirement: before inserting parsed , extracted info write info sets in xml file user validation , insert in database tables upon user acceptance.

how proceed ?

my c# parser component work flow:

protected void button1_click(object sender, eventargs e) { seek { string path = server.mappath("~/app_data" + "/" + "folder" + "/" + dropdownlist1.text + "/"); ifileparser fileparser = new defaultfileparser(first_inserted); string destinationtablename = "my table"; string sourcefilefullname = getfilefullname(path); ienumerable<datatable> datatables = fileparser.getfiledata(sourcefilefullname); foreach (datatable tbl in datatables) { fileparser.writechunkdata(tbl, destinationtablename, map()); } appln_parse_xml1(path); appln_parse_xml2(path); appln_parse_xml3(path); appln_parse_excel(path); } } private static bool appln_parse_xml3(string _xml3_path) { bool parse_status = false; dataclasses1datacontext dbcontext = new dataclasses1datacontext(); //xml file list<string> xml3 = system.io.directory.getfiles(@_xml3_path, "*.xml", searchoption.alldirectories).tolist<string>(); foreach (var _files in xml3) { var xdoc = xdocument.load(_files); xnamespace ns = xdoc.root.getdefaultnamespace(); var groups = g in xdoc.descendants(ns + "group") (string)g.attribute("name") == "model name" select new first_dbml { comp_value = decimal.parse((from c in g.elements(ns + "group").descendants(ns + "cell") (string)c.attribute("c") == "0" select c.value).first()), }; dbcontext.first_dbmls.insertallonsubmit(groups); //before insertion need write in xml comp_value user validation dbcontext.submitchanges(); // inserting my_table }

as per understanding of question, can perform following. in appln_parse_xml3 function, saving parsed objects database using dbcontext.first_dbmls.insertallonsubmit(groups); here instead of saving this, can bind objects repeater control. repeater shall show parsed objects, take button each object. can display the properties of each object in repeater item, user able justice whether take or not accept. if want display xml user, can serialize objects xml , display them in repeater.

once user clicks accept, can create grouping object repeater item , save database. if displaying object xml then, can de serialize xml object , save database.

to serialize object xml can utilize next function.

private string serialize(object value) { system.iformatprovider provider = system.globalization.cultureinfo.currentculture; stringbuilder builder = new stringbuilder(); string serializedstring = string.empty; seek { xmlserializer xs = new xmlserializer(value.gettype()); xmlwriter xmltextwriter = xmltextwriter.create(builder); xs.serialize(xmltextwriter, value); serializedstring = builder.tostring(); xmltextwriter.close(); } grab (exception ex) { serializedstring = "serialization exception : " + ex.message + ex.stacktrace; } homecoming serializedstring; }

you can convert xml object using next code

xmlserializer serializer = new xmlserializer(typeof(first_dbml)); first_dbml ei = (first_dbml)serializer.deserialize(new stringreader(xmlstring));

i hope understood properly.

c# xml linq

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -