c# - Issue with reading multiple xml nodes instead of one -


the xml bills have 1 node returned , parsed. have come across issue xml bill had multiple nodes. since code not set handle that, customer ended incorrect bill.

this code have goes through bill list. if comes node parses information xml.

    var response = new list<customerbill>();     try     {         foreach (getbillforcaresponse ebillresponse in ebillresponselist)         {             var statementdetailsresponse =   getstatementdetails(                 new getstatementdetailsrequest                 {                    batchid = ebillresponse.batchid,                    customeraccountid =    ebillresponse.ca.tostring("000000000"),                    statementid =   ebillresponse.cas_num.tostring("0000")                 });             string xmlbill = statementdetailsresponse.statementasxml.tostring();            var document = new xmldocument();            document.loadxml(xmlbill);             var sadetailedpagenode = xmlbillparser.getdetailpagesectionbysa(requestsa, xmlbill);            if (sadetailedpagenode == null) continue;             var customerbill = new customerbill();            customerbill.issurepay = xmlbillparser.getsurepayflagfrombill(document);            customerbill.serviceaddress = xmlbillparser.getserviceaddress(requestsa, document);            customerbill.monthname = xmlbillparser.getnillstatementdate(requestsa, xmlbill);            customerbill.eqcurlplanbal = xmlbillparser.getequalizercurrentplanbalance(document);            customerbill.eqpymntdue = xmlbillparser.getequalizerpaymentdue(document);             customerbill.service = getserviceaccountusageandbillingdetail(requestsa, xmlbill, sadetailedpagenode);            response.add(customerbill);         }     }     catch (exception ex)     {         trace.write(new invalidoperationexception(requestsa, ex));     }     return response; } 

here method checks if there node in xml. have changed code returns nodes. had change type xmlnode xmlnodelist because returning collection of nodes. ****this whats causing problems in code in other places.***

public static xmlnode getdetailpagesectionbysa(string sa, string statementxml) {     xmldocument document = new xmldocument();     document.loadxml(statementxml);     string requestsa = sa.padleft(9, '0');     string xpath = string.format("//para[irbilgp_sa_saa_id_print.service.account.statment='{0}s{1}']/..", requestsa.substring(0, 4), requestsa.substring(4));     return document.selectnodes(xpath);     //var nodes = document.selectnodes(xpath);    // if(nodes.count > 0) return nodes[nodes.count - 1];     //if(!saexistinbill(requestsa, statementxml)) return null;     //var node = getdetailpagesectionbybillprisminfoindex(sa, statementxml);     //if (node != null) return node;     //return null; } 

so returning called.. im getting invalid arguement here customerbill.service = getserviceaccountusageandbillingdetail(requestsa, xmlbill, sadetailedpagenode); because parameter sadetailedpagenode xmlnodelist when expecting of type xmlnode. if go method private static serviceaddressbilldetail getserviceaccountusageandbillingdetail(string requestsa, string xmlbill, xmlnode detailpagenode) added @ end of code see. if change parameter xmlnode detailpagenode xmlnodelist detailpagenode have fix invalid arguement above, detailpagenode.selectnodes becomes invalid because xmlnodelist not have selectnodes extension method. use extention method lot through method. getting lot of errors.

           var sadetailedpagenode = xmlbillparser.getdetailpagesectionbysa(requestsa, xmlbill);            if (sadetailedpagenode == null) continue;             var customerbill = new customerbill();            customerbill.issurepay = xmlbillparser.getsurepayflagfrombill(document);            customerbill.serviceaddress = xmlbillparser.getserviceaddress(requestsa, document);            customerbill.monthname = xmlbillparser.getnillstatementdate(requestsa, xmlbill);            customerbill.eqcurlplanbal = xmlbillparser.getequalizercurrentplanbalance(document);            customerbill.eqpymntdue = xmlbillparser.getequalizerpaymentdue(document);             customerbill.service = getserviceaccountusageandbillingdetail(requestsa, xmlbill, sadetailedpagenode);            response.add(customerbill);         }     }     catch (exception ex)     {         trace.write(new invalidoperationexception(requestsa, ex));     }     return response; }     private static serviceaddressbilldetail getserviceaccountusageandbillingdetail(string requestsa, string xmlbill, xmlnode detailpagenode)     {         var sabilldetail = new serviceaddressbilldetail();         sabilldetail.usageservicename = requestsa;          var meterreadendxmlnodes = detailpagenode.selectnodes("usage_kwh_b");           if (meterreadendxmlnodes.count == 0)         {             meterreadendxmlnodes = detailpagenode.selectnodes("usage_kwh_a");         }         if (meterreadendxmlnodes.count == 0)         {             meterreadendxmlnodes = detailpagenode.selectnodes("apselec_kwh_b");         }         if (meterreadendxmlnodes.count == 0)         {             meterreadendxmlnodes = detailpagenode.selectnodes("apselec_kwh_a");         }          var demandxmlnodes = detailpagenode.selectnodes("usage_kw_total_bold"); 

how can fix invalid arguments can use xmlnodelist instead of xmlnode? there way convert or cast? or there xml object can use?

since returning multiple nodes. know need loop through customerbill portion. how can without creating new bill every node? nodes in 1 xml need included in 1 bill.

from code you've provided, part needs account refactor xmlnodelist getserviceaccountusageandbillingdetail(), have 2 options:

  1. update getserviceaccountusageandbillingdetail() take in xmlnodelist parameter instead , aggregate values inside method come final serviceaddressbilldetail object.
  2. loop through xmlnode objects in xmlnodelist , reconcile different serviceaddressbilldetail objects yourself.

without details on serviceaddressbilldetail, can guess better, i'd suggest using first option.

private static serviceaddressbilldetail getserviceaccountusageandbillingdetail(     string requestsa,      string xmlbill,      xmlnodelist detailpagenodes) {    var sabilldetail = new serviceaddressbilldetail();    sabilldetail.usageservicename = requestsa;      foreach(xmlnode detailpagenode in detailpagenodes)     {         var meterreadendxmlnodes = detailpagenode.selectnodes("usage_kwh_b");           if (meterreadendxmlnodes.count == 0)         {             meterreadendxmlnodes = detailpagenode.selectnodes("usage_kwh_a");         }         if (meterreadendxmlnodes.count == 0)         {             meterreadendxmlnodes = detailpagenode.selectnodes("apselec_kwh_b");         }         if (meterreadendxmlnodes.count == 0)         {             meterreadendxmlnodes = detailpagenode.selectnodes("apselec_kwh_a");         }          var demandxmlnodes = detailpagenode.selectnodes("usage_kw_total_bold");         //whatever comes next     } } 

assuming serviceaddressbilldetail has properties "usage" add appropriate values each detailpagenode sabilldetail object.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -