c# - Deserializing XML gives me null instead of the object -


this xml:

<?xml version="1.0" encoding="utf-8"?> <!doctype paymentservice public "-//worldpay//dtd worldpay paymentservice v1//en"                                 "http://dtd.worldpay.com/paymentservice_v1.dtd"> <paymentservice version="1.4" merchantcode="abc">     <reply>         <error code="4">             <![cdata[security violation]]>         </error>     </reply> </paymentservice> 

i'm deserializing classes created using xsd provided:

var responsestreamreader = new streamreader(response.getresponsestream());  xmlrootattribute xroot = new xmlrootattribute(); xroot.elementname = "paymentservice";  xmlserializer myserializer = new xmlserializer(typeof(paymentservice), xroot);  var someresponse = (paymentservice) myserializer.deserialize(responsestreamreader); 

it deserializes paymentservice, version, merchantcode, item property null.

this part of schema:

[system.codedom.compiler.generatedcodeattribute("xsd", "4.0.30319.33440")] [system.serializableattribute()] [system.diagnostics.debuggerstepthroughattribute()] [system.componentmodel.designercategoryattribute("code")] [system.xml.serialization.xmltypeattribute(anonymoustype = true, namespace = "http://tempuri.org/worldpa [system.xml.serialization.xmlrootattribute(namespace = "http://tempuri.org/worldpay", isnullable = false public partial class paymentservice {      private object itemfield;      private paymentserviceversion versionfield;      private string merchantcodefield;      /// <remarks/>     [system.xml.serialization.xmlelementattribute("inquiry", typeof (inquiry))]     [system.xml.serialization.xmlelementattribute("modify", typeof (modify))]     [system.xml.serialization.xmlelementattribute("notify", typeof (notify))]     [system.xml.serialization.xmlelementattribute("reply", typeof (reply))]     [system.xml.serialization.xmlelementattribute("submit", typeof (submit))]     [system.xml.serialization.xmlelementattribute("verify", typeof (verify))]     public object item     {         { return this.itemfield; }         set { this.itemfield = value; }     }      /// <remarks/>     [system.xml.serialization.xmlattribute]     public paymentserviceversion version     {         { return this.versionfield; }         set { this.versionfield = value; }     }      /// <remarks/>     [system.xml.serialization.xmlattribute(datatype = "nmtoken")]     public string merchantcode     {         { return this.merchantcodefield; }         set { this.merchantcodefield = value; }     } } 

i expect item reply object.

what doing wrong?

i've fixed this, possibly not in best way, benefit of others..

i removed namespaces everything.

my schema generated xsd.exe , removed references namespace = "http://tempuri.org/worldpay", , fixed it. meant didn't have mess around xmlrootattribute.


Comments