Reputation: 37
Im having an issue with my code and was hoping i could get some assistance from you. I have a method that is of type XmlNodeList (GetDetailPageSectionBySA), now that method is used as one of the parameters in another method. But that method (GetServiceAccountusageAndBillingDetail) is expecting a type of XmlNode for that parameter(saDetailedPageNode). If i change that data type to XmlNodeList for that parameter then it messes up a whole bunch of stuff down the line where only XmlNode can be used.
Why dont I just change the type of the first method (GetDetailPageSectionBySA) to XmlNode and solve all my issues you ask? Because that type can only return one node and that method returns a collection of nodes and needs to use XmlNodeList.
So im just wondering if there is any ways to convert or cast XmlNodeList to XmlNode and if so how is it done?
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);// This is the method of type XmlNodeList
if (saDetailedPageNode == null) continue;
var customerBill = new CustomerBill();
customerBill.IsSurepay = XmlBillParser.GetSurepayFlagFromBill(document);
customerBill.ServiceAddress = XmlBillParser.GetServiceAddress(requestSA, document);
customerBill.MonthName = XmlBillParser.GetBillStatementDate(requestSA, xmlBill);
customerBill.EqCurPlanBal = XmlBillParser.GetEqualizerCurrentPlanBalance(document);
customerBill.EqPymntDue = XmlBillParser.GetEqualizerPaymentDue(document);
****customerBill.Service = GetServiceAccountUsageAndBillingDetail(requestSA, xmlBill, saDetailedPageNode);// This is where the invalid argument is because saDetailedPageNode should be of type XmlNode
response.Add(customerBill);
}
I have put **** where the issue is as well as comments on those lines. I am a beginner in coding and any help would be great. Thanks in advanced.
Upvotes: 0
Views: 1252
Reputation: 5904
There is no such thing as casting an XmlNodeList
to an XmlNode
. An XmlNodeList
is, as the name suggests, a list of XmlNode
s. So, if you want to do something with the XmlNode
s in the list, you will have to go through the list and perform some action on every node in that list.
In your case, I suspect GetDetailPageSectionBySA
could return multiple sections from the bill. If so, you could add a foreach
loop:
foreach (GetBillForCAResponse eBillResponse in eBillResponseList)
{
// removed code for brevity
foreach(var saDetailedPageNode =x mlBillParser.GetDetailPageSectionBySA(requestSA, xmlBill)
{
var customerBill = new CustomerBill();
customerBill.IsSurepay = XmlBillParser.GetSurepayFlagFromBill(document);
customerBill.ServiceAddress = XmlBillParser.GetServiceAddress(requestSA, document);
customerBill.MonthName = XmlBillParser.GetBillStatementDate(requestSA, xmlBill);
customerBill.EqCurPlanBal = XmlBillParser.GetEqualizerCurrentPlanBalance(document);
customerBill.EqPymntDue = XmlBillParser.GetEqualizerPaymentDue(document);
customerBill.Service = GetServiceAccountUsageAndBillingDetail(requestSA, xmlBill, saDetailedPageNode)
response.Add(customerBill);
}
}
Upvotes: 0