C# XML Serialization Not working -


i have following code supposed deserialize xml string class has of items in xml file, may not have them fine should assume null.

when run following code using xml below leaves each value null.

any pointers i'm going wrong

thanks

serviceresponse returnval = new serviceresponse();  try {     xmlserializer serializer = new xmlserializer(typeof(serviceresponse));      stringreader sr = new stringreader(xmlresponse);      namespaceignorantxmltextreader xmlwithoutnamespace = new namespaceignorantxmltextreader(sr);      returnval = (serviceresponse)serializer.deserialize(xmlwithoutnamespace);  } catch (exception ex) {     throw ex; }   [xmlroot("serviceresponse")] public class serviceresponse {     public string requesttype { get; set; }      public string applicationsender { get; set; }      public string workstationid { get; set; }      public string popid { get; set; }      public string requestid { get; set; }      public string referencenumber { get; set; }      public string protocolversion { get; set; }      public string devicetype { get; set; }      public string swchecksum { get; set; }      public string communicationprotocol { get; set; }      public string model { get; set; }      public string applicationsoftwareversion { get; set; }      public string manufacturer_id { get; set; }      public string overallresult { get; set; }  }  public class namespaceignorantxmltextreader : xmltextreader {     public namespaceignorantxmltextreader(system.io.textreader reader) : base(reader) { }      public override string namespaceuri     {         { return ""; }     } }    

xmlresponse equal following:

<?xml version="1.0" encoding="utf-8" standalone="no"?><serviceresponse requesttype="login" applicationsender="qwerty" workstationid="1" requestid="1254" protocolversion="12" devicetype="1" swchecksum="1" communicationprotocol="11" model="1" applicatiosoftwareversion="010" manufacturer_id="0" overallresult="success" xmlns="http://www.nrf-arts.org/ixretail/namespace" xmlns:ifsf="http://www.ifsf.org/" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://www.nrf-arts.org/ixretail/namespace c:\schema\serviceresponse.xsd" /> 

all properties attributes, , xmlserializer interpret them elements unless tell otherwise.

add [xmlattribute] attributes each of properties , work.

as aside, throw ex dump stack trace , isn't want - see this question further detail. if you're not going exception, removing try/catch entirely better.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -