I have a structure of the object, which I'm trying to convert to the xml, which results in duplicated level node. I'm pretty sure this has something to do with the subclass because I had to implement my deserialization, but I'm not sure what is going on in the other direction. The same xml structure is used as input when deserializing my data when the application starts, since it will be saved later when reinitializing.
Here, it looks like an erroneous conclusion xml:
<Keyboarding xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Exercises>
<Exercise>
<Exercise Id="3" ActivityNumber="5" SubActivityNumber="b" Type="Standard">
<Title>Test Title</Title>
<Instructions>Downloaded Update Instructions</Instructions>
</Exercise>
</Exercise>
</Exercises>
</Keyboarding>
Here it should look (and looks like the initial deserialization):
<Keyboarding xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Exercises>
<Exercise Id="3" ActivityNumber="5" SubActivityNumber="b" Type="Standard">
<Title>Test Title</Title>
<Instructions>Downloaded Update Instructions</Instructions>
</Exercise>
</Exercises>
</Keyboarding>
. - , Type. XML- , , .
, XML-:
[XmlArray("Exercises")]
[XmlArrayItem("Exercise", Type = typeof (ExerciseXmlSerializer<Exercise>))]
public Collection<Exercise> UnprocessedExercises { get; set; }
:
[Serializable]
[XmlType(AnonymousType = true)]
public class Exercise
:
[Serializable]
[XmlType(AnonymousType = true)]
[XmlRoot(ElementName = "Exercise", IsNullable = false)]
public class StandardExercise : Exercise
XML-:
public class ExerciseXmlSerializer<T> : IXmlSerializable where T : class
{
private T _data;
...
public void WriteXml(XmlWriter writer)
{
Type type = _data.GetType();
new XmlSerializer(type).Serialize(writer, _data);
}
...
}
WriteXml() , node ? ?