I have class that implement list of custom class. That class also has two properties. But when I serialize that class, XML contains only array of my custom classes but don\'
I've uploaded my serialization library to Github, where such issues are handled.
Atlas Xml Serializer
I'm assuming that you have below data classes. I've just added [XmlElement] attribute over properties to force them serialize into xml elements.
public class Porudzbina : List, IEnumerable
{
[XmlElement]
public long KomSifra { get; set; }
[XmlElement]
public Guid KomId { get; set; }
IEnumerator IEnumerable.GetEnumerator()
{
var sqlRow = new SqlDataRecord(
new SqlMetaData("rb", SqlDbType.Int),
new SqlMetaData("RobaSifra", SqlDbType.NVarChar, 50),
new SqlMetaData("RobaNaziv", SqlDbType.NVarChar, 100)
);
foreach (PorudzbenicaStavka por in this)
{
sqlRow.SetInt32(0, por.rb);
sqlRow.SetString(1, por.RobaSifra);
sqlRow.SetString(2, por.RobaNaziv);
yield return sqlRow;
}
}
}
public class PorudzbenicaStavka
{
[XmlElement]
public int rb { get; set; }
[XmlElement]
public string RobaSifra { get; set; }
[XmlElement]
public string RobaNaziv { get; set; }
}
And here's the instance:
var o = new Porudzbina
{
new PorudzbenicaStavka { rb=1, RobaSifra="3702", RobaNaziv="Foullon mlecna cokolada 33% Ecuador 100g" },
new PorudzbenicaStavka { rb=2, RobaSifra="1182", RobaNaziv="IL Capitano zelena maslina sa paprikom 720g" },
new PorudzbenicaStavka { rb=3, RobaSifra="1120", RobaNaziv="Kaiser tuna steak sa papricicom u ulju 170g." },
};
o.KomId = new Guid("{EC63AEC3-1512-451F-B967-836DD0E9820A}");
o.KomSifra = 999999;
And here's how atlas xml serialization library does the job:
var serialized = Atlas.Xml.Serializer.Serialize(o, true);
var deserialized = Atlas.Xml.Serializer.Deserialize(serialized);
Xml would look like this:
999999
ec63aec3-1512-451f-b967-836dd0e9820a
-
1
3702
Foullon mlecna cokolada 33% Ecuador 100g
-
2
1182
IL Capitano zelena maslina sa paprikom 720g
-
3
1120
Kaiser tuna steak sa papricicom u ulju 170g.
If you change the data class like this:
[Atlas.Xml.XmlSerializationType(ChildElementName = "PorudzbenicaStavka")]
public class Porudzbina : List, IEnumerable
{
public long KomSifra { get; set; }
public Guid KomId { get; set; }
// ...
}
public class PorudzbenicaStavka
{
public int rb { get; set; }
public string RobaSifra { get; set; }
[XmlText]
public string RobaNaziv { get; set; }
}
Then, serialized class would be like this:
Foullon mlecna cokolada 33% Ecuador 100g
IL Capitano zelena maslina sa paprikom 720g
Kaiser tuna steak sa papricicom u ulju 170g.