-3

Below is the my source xml. i want to write c# class for it and then deserialize it. so i can use c# object and save this to database. History- : i was doing json deserialize that works great but am running into issue in my xml 'LastChangeId' node can be part of this xml , sometime may not be there at all or sometime there are multiple nodes for it. this issue messing with my json parsing. and i have to switch back to xml. any help will appreciable.

<FundingSource    >
  <ClientAccountPaySourceId>16</ClientAccountPaySourceId>
  <ClientAccountId>67</ClientAccountId>
  <ClientAccountName>Default Account</ClientAccountName>
  <PrimaryPartyId>62</PrimaryPartyId>
  <PrimaryRoleId>1290</PrimaryRoleId>
  <TenderTypeId>3</TenderTypeId>
  <TenderTypeName>Credit Card</TenderTypeName>
  <TenderInterfaceName>Credit Card</TenderInterfaceName>
  <CreditCareTypeName>Visa</CreditCareTypeName>
  <ChargeAccountMask>1111</ChargeAccountMask>
  <ExpirationDate>04/20</ExpirationDate>
  <BillingAccountName>Joe Montana</BillingAccountName>
  <BillingStreet>1235 Main St</BillingStreet>
  <BillingCity>Pleasanton</BillingCity>
  <BillingPostalCode>94588</BillingPostalCode>
  <BillingCountry>US</BillingCountry>
  <BillingTelephone>1231234567</BillingTelephone>
  <DisplayOrder>1</DisplayOrder>
  <UseForRecurring>true</UseForRecurring>
  <UseForNonRecurring>true</UseForNonRecurring>
  <IsActive>true</IsActive>
  <Invalid>false</Invalid>
  <ChargeAccountToken>VC84632147254611111111</ChargeAccountToken>
  <IsExternal>false</IsExternal>
  <LastChangeId   >
    <ClientAccountPaySourceId>16</ClientAccountPaySourceId>
    <TimeUtc>2016-02-02 01:04:16</TimeUtc>
    <TimeLocal>2016-02-01 17:04:16</TimeLocal>
    <UserName>Josh.Lyon</UserName>
    <PartyId>20</PartyId>
    <RoleId>1160</RoleId>
    <BusinessUnitCode>2</BusinessUnitCode>
    <EndpointKey>default</EndpointKey>
  </LastChangeId>
</FundingSource>
Amrik
  • 446
  • 5
  • 14
  • 1
    Possible duplicate of [How to serialize/deserialize simple classes to XML and back](http://stackoverflow.com/questions/3356976/how-to-serialize-deserialize-simple-classes-to-xml-and-back) – Matt Feb 09 '16 at 04:15

1 Answers1

0
public class FundingSource {
public int ClientAccountPaySource {get; set;}
public int ClientAccountId {get; set;}
public string ClientAccountName {get; set;}
...
}
//Use it like so:
System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(p.GetType());

x.Serialize(Console.Out, new FundingSource() { ClientAccountPaySource=1, ClientAccountId=100, ClientAccountName="Name"});

For more, see the MSDN Page on XML Serialization or the number of related questions like this one

Community
  • 1
  • 1
Matt
  • 621
  • 1
  • 6
  • 24
  • Care to explain the downvote? While it's a simple question that's been answered I provided the info that was required and a link to the MSDN page and a related question – Matt Feb 09 '16 at 04:19