I am learning XML serialization and responding to a problem, I have two claess
[System.Xml.Serialization.XmlInclude(typeof(SubClass))]
public class BaseClass
{
}
public class SubClass : BaseClass
{
}
I am trying to serialize a SubClass object to an XML file, I am using beat code
XmlSerializer xs = new XmlSerializer(typeof(Base));
xs.Serialize(fs, SubClassObject);
I noticed that Serialization was successful, but the XML file is similar to
<?xml version="1.0"?>
<BaseClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:type="SubClass">
...
</Employee>
If i use
XmlSerializer xs = new XmlSerializer(typeof(Base));
SubClassObject = xs.Deserialize(fs) as SubClass;
I noticed that he would complain about xsi: type is an unknown attribute (I registered an event), although all the information embedded in XML was successfully parsed and the members in SubClassObject were restored correctly.
Does anyone know why an error occurs while parsing xsi: type and something that I did wrong?
thank
source
share