Click here to Skip to main content
14,661,076 members
Rate this:
Please Sign up or sign in to vote.
See more:
hello, iam new to c#, i have requirement on windows form xml serialization and deserialization.i have done on serialization object to xml it is working fine.but deserialization i am not getting full xml what we have save earlier by using serialization.can any one help me plz please.
save xml is working, but how to retrive that xml using Deserialization

TradeTicket>
------------
------------
-------------
/TradeTicket>


SwapLegA
-----------
-----------
-----------
-----------
/SwapLegA>

SwaplegB>
--------
---------
--------
/SwaplegB>

/TradeTicket>
private void btnSerialize_Click(object sender, EventArgs e)
{
 TradeTicket t = new TradeTicket()
 {
--------
---------
 }
t.Positions.Add(new SwapLegA())
{
-----------
-----------
}

t.Positions.Add(new SwapLegB())
{
-------------
----------------
}


  XmlAttributeOverrides specific_attributes = new XmlAttributeOverrides();
            XmlAttributes attrs = new XmlAttributes();
            attrs.XmlElements.Add(new XmlElementAttribute(typeof(SwapLegA)));
            attrs.XmlElements.Add(new XmlElementAttribute(typeof(SwapLegB)));
            specific_attributes.Add(typeof(TradeTicket), "Positions", attrs);
            XmlSerializer ser = new XmlSerializer(typeof(TradeTicket), specific_attributes);
                       
            XmlDocument serDoc = new XmlDocument();
            //XmlSerializer ser = new XmlSerializer(st.GetType());
            StringBuilder sb = new StringBuilder();
            StringWriter writer = new StringWriter(sb);

            ser.Serialize(writer, t);
            serDoc.LoadXml(sb.ToString());            
            MessageBox.Show(serDoc.OuterXml);
            serDoc.Save("D:\\SwapTicketAB.xml");
}



At the time of deserialization i am getting only TradeTicket fields
any plz tel please tell me how to get full xml with swaplegs.
Thanks in Advance.
Posted
Updated 10-May-12 19:56pm
v5
Comments
Bernhard Hiller 11-May-12 4:06am
   
You showed as the function for serializing which - you say - is working (did you open your xml file in an editor and saw that it was correct?). We need the *DE*serialization function to find out what's going wrong.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Nice CodeProject article is available at XML Serialization and deSerialization[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100