Reading XML Decedents to List

  • Thread starter Thread starter Born2Achieve
  • Start date Start date
B

Born2Achieve

Guest
Hi,

Below is one of the portion of my xml and i would like to convert the node value to c# class object.

<resultArtifacts xsi:type="soapenc:Array" soapenc:arrayType="xsd:string[2]" xmlns:ns3="http://www.w3.org/2002/12/soap-encoding" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<item>[TCHistoryInquiryByCardDto][MCC][/MCC][amount]$ 20.00[/amount][compDate]20250000[/compDate][date]06/24/2019[/date][description][/description][merchantID][/merchantID][rejectCode][/rejectCode][substantiationIndicator][/substantiationIndicator][time]20:25:00[/time][transactionCode]0230[/transactionCode][transactionType]0138[/transactionType][/TCHistoryInquiryByCardDto]</item>
<item>[TCHistoryInquiryByCardDto][MCC]PRK[/MCC][amount]$ 20.00[/amount][compDate]14242200[/compDate][date]06/25/2019[/date][description]PRK-10630560[/description][merchantID][/merchantID][rejectCode][/rejectCode][substantiationIndicator][/substantiationIndicator][time]14:24:22[/time][transactionCode]0210[/transactionCode][transactionType]0133[/transactionType][/TCHistoryInquiryByCardDto]</item>
</resultArtifacts>



c# Class :

public class TCHistoryInquiryByCardDto
{
public string MCC { get; set; }

public string Amount { get; set; }

public string CompDate { get; set; }

public string Date { get; set; }

public string Description { get; set; }

public string MerchantID { get; set; }

public string RejectCode { get; set; }

public string SubstantiationIndicator { get; set; }

public string Time { get; set; }

public string TransactionCode { get; set; }

public string TransactionType { get; set; }
}

My Try :

students = doc.Descendants("resultArtifacts").Descendants("item").Descendants("TCHistoryInquiryByCardDto").Select(d =>
new TCHistoryInquiryByCardDto
{
MCC = d.Element("MCC").Value,
Amount = d.Element("Name").Value,
CompDate = d.Element("Section").Value

}).ToList();


but am getting count as 0. any help would be highly appreciated. how to convert the node values to list of class



loving dotnet

Continue reading...
 
Back
Top