c# - XML enum deserialization -
i have c# enum generated following xsd.
<xsd:schema xmlns:xsd="http://www.w3.org/2001/xmlschema"> <xsd:element name="mails" type="mailstype" /> <xsd:complextype name="mailstype"> <xsd:sequence minoccurs="0" maxoccurs="unbounded"> <xsd:element name="mail" type="mailtype" /> </xsd:sequence> </xsd:complextype> <xsd:complextype name="mailtype"> <xsd:sequence> <xsd:element name="envelope" type="envelopetype" /> <xsd:element name="body" type="bodytype" /> <xsd:element name="attachment" type="attachmenttype" minoccurs="0" maxoccurs="unbounded" /> </xsd:sequence> <xsd:attribute use="required" name="id" type="xsd:integer" /> </xsd:complextype> <xsd:element name="header"> <xsd:complextype> <xsd:simplecontent> <xsd:extension base="xsd:string"> <xsd:attribute ref="name" use="required" /> </xsd:extension> </xsd:simplecontent> </xsd:complextype> </xsd:element> <xsd:element name="date" type="xsd:datetime" /> <xsd:complextype name="envelopetype"> <xsd:sequence> <xsd:element name="from" type="xsd:string" /> <xsd:element name="to" type="xsd:string" /> <xsd:element ref="date" /> <xsd:element name="subject" type="xsd:string" /> <xsd:element ref="header" minoccurs="0" maxoccurs="unbounded" /> </xsd:sequence> <xsd:attribute name="from" type="xsd:string" use="required" /> </xsd:complextype> <xsd:simpletype name="bodytype"> <xsd:restriction base="xsd:string" /> </xsd:simpletype> <xsd:complextype name="attachmenttype"> <xsd:group ref="attachmentcontent" /> <xsd:attribute ref="name" use="required" /> </xsd:complextype> <xsd:group name="attachmentcontent"> <xsd:sequence> <xsd:element name="mimetype"> <xsd:complextype> <xsd:attributegroup ref="mimetypeattributes" /> </xsd:complextype> </xsd:element> <xsd:element name="content" type="xsd:string" minoccurs="0" /> </xsd:sequence> </xsd:group> <xsd:attribute name="name" type="xsd:string" /> <xsd:attributegroup name="mimetypeattributes"> <xsd:attribute name="type" type="mimetopleveltype" use="required" /> <xsd:attribute name="subtype" type="xsd:string" use="required" /> </xsd:attributegroup> <xsd:simpletype name="mimetopleveltype"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="text" /> <xsd:enumeration value="multipart" /> <xsd:enumeration value="application" /> <xsd:enumeration value="message" /> <xsd:enumeration value="image" /> <xsd:enumeration value="audio" /> <xsd:enumeration value="video" /> </xsd:restriction> </xsd:simpletype> </xsd:schema>
i have c# code:
/// <remarks/> [system.codedom.compiler.generatedcodeattribute("xsd", "4.0.30319.1")] [system.serializableattribute()] public enum mimetopleveltype { /// <remarks/> text, /// <remarks/> multipart, /// <remarks/> application, /// <remarks/> message, /// <remarks/> image, /// <remarks/> audio, /// <remarks/> video, }
and have xml (sketched):
<mails> <mail id="0"> ... <attachment name="signature.doc"> <mimetype type="application " subtype="msword"/> <content> ### removed spamoracle ### </content> </attachment> </mail> </mails>
when try deserialize xml c# object, following error:
there error in xml document (14, 17).
apparently problem xml has element attribute "application" , cannot convert enum type.
is there can suggest solution problem?
and no wonder - have
type="application "
instead of
type="application"
notice whitespace @ end of attribute.
Comments
Post a Comment