Click here to Skip to main content
15,895,557 members
Please Sign up or sign in to vote.
2.00/5 (1 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>
C#
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

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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900