XML Deserialization

Stanley Tweedle posted at 09-May-08 03:57
How do I deserialize the following XML:

    <InvestmentHolding InvestmentAccount="4015445" BookValue="+0000000000">
      <InvestmentTransaction InvestmentAccount="4015445" IncreaseDecrease="I"/>
      <InvestmentTransaction InvestmentAccount="4015445" IncreaseDecrease="I"/>
      <InvestmentTransaction InvestmentAccount="4015445" IncreaseDecrease="D"/>
      <InvestmentTransaction InvestmentAccount="4015445" IncreaseDecrease="D"/>
      <InvestmentTransaction InvestmentAccount="4015445" IncreaseDecrease="D"/>
    </InvestmentHolding>

...into the InvestmentHolding object specified by the
InvestmentHolding class below:

    [XmlType("InvestmentHolding")]
    public class InvestmentHolding
    {
        private string investmentAccount;
        private string bookValue;
        private IList<InvestmentTransaction> investmentTransactions;

        [XmlAttribute("InvestmentAccount")]
        public string InvestmentAccount
        {
            get { return investmentAccount; }
            set { investmentAccount = value; }
        }
        [XmlAttribute("BookValue")]
        public string BookValue
        {
            get { return bookValue; }
            set { bookValue = value; }
        }
       
        public IList<InvestmentTransaction> InvestmentTransactions
        {
            get { return investmentTransactions; }
            set { investmentTransactions = value; }
        }         
    }

    [XmlType("InvestmentTransaction")]
    public class InvestmentTransaction
    {
        private string investmentAccount;
        private string increaseDecrease;

        [XmlAttribute("InvestmentAccount")]
        public string InvestmentAccount
        {
            get { return investmentAccount; }
            set { investmentAccount = value; }
        }
        [XmlAttribute("IncreaseDecrease")]
        public string IncreaseDecrease
        {
            get { return increaseDecrease; }
            set { increaseDecrease = value; }
        }
    }

Click here to sign in and reply. You could earn money via our $500 contest just for being helpful.
  XML Deserialization - Stanley Tweedle  09-May-08 03:57 3:57:31 PM
      short example - Peter Bromberg  09-May-08 08:34 8:34:27 PM
      Re: XML Deserialization - Chirag Bhavsar  10-May-08 02:06 2:06:21 AM
      in this way - santhosh kapa  10-May-08 02:54 2:54:49 AM
      Try this sample for c# manual deserialization - Aravind Kumar  11-May-08 05:44 5:44:33 AM
View Posts