I am creating an object class from an XML file and then would like to assign one field which is not int the XML file, namely: Color
.
My serialization is as follows:
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public partial class pack
{
public steps steps { get; set; }
}
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public partial class steps
{
readonly ChildCollection<step> Steps;
[System.Xml.Serialization.XmlElementAttribute("step")]
public Collection<step> StepList { get { return Steps; } }
}
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public partial class step
{
[System.Xml.Serialization.XmlElementAttribute("step")]
public Collection<step> StepList { get { return Steps; } }
[System.Xml.Serialization.XmlAttributeAttribute("name")]
public string Name { get; set; }
[System.Xml.Serialization.XmlAttributeAttribute("id")]
public string Id { get; set; }
[System.Xml.Serialization.XmlAttributeAttribute("Color")]
public System.Drawing.Color Color { get; set; }
}
As you see, in the last line from the code I am creating a color field and then in the other function will assign some variable color for that.
pack XmlFilePack = new pack();
using (FileStream stream = File.OpenRead(@"Steps_1.xml"))
{
try
{
XmlSerializer serializer = new XmlSerializer(typeof(pack));
XmlFilePack = (pack)serializer.Deserialize(stream);
}
finally
{
//close file
stream.Close();
}
}
But I have always null
for the XmlFilePack
. Does anyone know where is the error?
Update: Here is the XML file:
<pack >
<steps>
<step id ="12" name="S1" >
</step>
<step id ="1" name="S1" >
<step id ="2" name="S11" >
<step id ="3" name="S111" >
<step id ="5" name="S1121" >
</step>
</step>
</step>
<step id ="6" name="S12" >
<step id ="4" name="S112" >
<step id ="14" name="S112" >
</step>
</step>
</step>
</step>
</steps>
</pack>