Pablo Costa

Pablo Costa

  • NA
  • 24
  • 4.8k

Trouble to serialize XML with classes and a list

Feb 25 2016 10:15 AM

I'm trying to serialize a list , with a few other classes - but its always serializing only data from the list, instead of other classes and attributes.
Suppose i have:
[Serializable]
public class JMF
{
[XmlElement("SenderID")]
public string SenderID { get; set; }

[XmlElement("Version")]
public string Version { get; set; }

}

[XmlType("InkZoneProfile")]
public class xmldata //Class to receive items list
{
[XmlIgnore]
public string xml_filename { get; set; }

[XmlAttribute("Separation")]
public string colorname { get; set; }

[XmlAttribute("ZoneSettingsX")]
public string colorvalues { get; set; }
}

And serialize command:
XmlSerializer serializer = new XmlSerializer(typeof(List<xmldata>));
serializer.Serialize(Console.Out, xmlDataOfThisFile);

He's adding only the InkZoneProfile stuff - ignoring the JMF.

pastebin.com/KxHfiah3 - entire code is here. Just paste into a new project. Also on this link:drive.google.com/open?id=0BwU9_GrFRYrTT0ZTS2dRMUhIWms - there's a sample file - just make a copy of it for reading multiple files
What am i doing wront ? I suppose its because i'm serializing only the List<xmldata> type  - is that correct ?
If so how do i fix it ?