c# - What is the most efficient way of getting these XML nodes and then saving them to the web service? -
i know simplistic, haven't worked xml files yet. proper way go getting necessary xml nodes , saving them wsdl? please let me know if there's way can make more efficient/cleaner or easier.
code gets nodes xml document , puts them dictionary:
public filereference loadxmldoc(string strfile) { logger.log("loadxmldoc:" + strfile); filereference fileref = new filereference(); fileref.filename = strfile; //create xml document obj xmldocument inputxmldoc = new xmldocument(); fileref.isvalid = false; //load xml document #region try { inputxmldoc.xmlresolver = null; inputxmldoc.load(strfile);//load xml file string input = inputxmldoc.outerxml;//get string console.writeline("success,loaded xml"); logger.log("loaded xml:" + strfile); //xmlnodelist xlist = inputxmldoc.getelementsbytagname("nulogyfile"); //logger.log("got xlist, length = " + xlist.count); fileref.importlist = new dictionary<string, xmlnode>(); nodenames = new list<string>{ "orderid", "customerid", "customername" }; try { int = 0; foreach (string name in nodenames) { console.writeline("adding xml node " + name); if (inputxmldoc.getelementsbytagname(name) != null) { xmlnodelist xlist = inputxmldoc.getelementsbytagname(name); foreach (xmlnode node in xlist) { fileref.importlist.add(name, node); //add individual node within nodelist } } //add specified node xml doc else { nodenames.removeat(i); } i++; } } catch (exception ex) { } } catch (exception ex) { } }
code saving new invoice (gets dictionary info):
invoices.invoiceorder newinvoice = new invoices.invoiceorder(); if (fileref.importlist.containskey("orderid")) {newinvoice.orderid = convert.toint32(fileref.importlist["orderid"].innertext);} if (fileref.importlist.containskey("customername")) {newinvoice.customername = fileref.importlist["customername"].innertext;} if (fileref.importlist.containskey("customerid")) { newinvoice.customerid = convert.toint32(fileref.importlist["customerid"].innertext); } //save new invoices _service.saveinvoices(new[] { newinvoice });
Comments
Post a Comment