title: XMLSerializer fails to deserialize a xml document
body: <p>I am a newbie to C#. I have a java REST service which returns a xml response and I am trying to deserialize the xml document using C# XmlSerializer. A sample xml document response is pasted below.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"
   standalone="yes" ?&gt;  &lt;ns2:Document
   xmlns:ns2="http://hxps.honeywell.com/model/impl"
   xmlns:ns3="http://hxps.honeywell.com/datatypes/impl"
   type="PS"&gt;
   &lt;docId&gt;SamplePSDocument1&lt;/docId&gt; 
   &lt;fields
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:ns5="http://jaxb.dev.java.net/array"
   xsi:type="ns5:anyTypeArray"&gt;   &lt;item
   xsi:type="ns3:scalarFieldImpl"
   key="Name"&gt;
        &lt;value xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xsi:type="xs:string"&gt;HXPS A4&lt;/value&gt;
   &lt;/item&gt;   &lt;item
   xsi:type="ns3:scalarFieldImpl"
   key="Creation Date"&gt;
         &lt;value xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xsi:type="xs:string"&gt;20 April
   2007&lt;/value&gt;    &lt;/item&gt; &lt;/fields&gt;
   &lt;id&gt;fb92f871-1f3d-4fa4-ba24-5ae3af0a493f&lt;/id&gt;
   &lt;revision&gt;1-c75f688e212fb5341ebdbd22a3867c14&lt;/revision&gt;
  
   - &lt;version&gt;   &lt;majorVersionNumber&gt;1&lt;/majorVersionNumber&gt;
   &lt;minorVerisonNumber&gt;5&lt;/minorVerisonNumber&gt;
   &lt;/version&gt; &lt;/ns2:document&gt;
  </code></pre>
  
  <p>It works fine when I deserialize this xml document into Document object. My document class is pasted below</p>
  
  <pre><code>[System.SerializableAttribute()]
  [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://hxps.honeywell.com/model/impl", TypeName = "PSDocument")]
  [System.Xml.Serialization.SoapTypeAttribute(Namespace = "http://hxps.honeywell.com/model/impl", TypeName = "PSDocument")]
  [System.Xml.Serialization.XmlRootAttribute(Namespace = "http://hxps.honeywell.com/model/impl", ElementName = "Document")]
  
  public partial class PSDocument
  {
  
      private Com.Honeywell.Hxps.Sdk.Model.DocumentType _type;
      private string _description;
      private string _displayName;
      private string _docId;
      private Com.Honeywell.Hxps.Sdk.Model.Impl.VersionImpl _version;
      private object _fields;
      private string _revision;
      private string _id;
      /// &lt;summary&gt;
      ///  (no documentation provided)
      /// &lt;/summary&gt;
      [System.Xml.Serialization.XmlAttributeAttribute(AttributeName = "type")]
      [System.Xml.Serialization.SoapAttributeAttribute(AttributeName = "type")]
      public Com.Honeywell.Hxps.Sdk.Model.DocumentType Type
      {
          get
          {
              return this._type;
          }
          set
          {
              this._type = value;
          }
      }
  
      /// &lt;summary&gt;
      ///  Property for the XML serializer indicating whether the "Type" property should be included in the output.
      /// &lt;/summary&gt;
      [System.Xml.Serialization.XmlIgnoreAttribute]
      [System.Xml.Serialization.SoapIgnoreAttribute]
      [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
      public bool TypeSpecified
      {
          get
          {
              return this._type != Com.Honeywell.Hxps.Sdk.Model.DocumentType.NULL;
          }
          set
          {
              if (!value)
              {
                  this._type = Com.Honeywell.Hxps.Sdk.Model.DocumentType.NULL;
              }
          }
      }
      /// &lt;summary&gt;
      ///  (no documentation provided)
      /// &lt;/summary&gt;
      [System.Xml.Serialization.XmlElementAttribute(ElementName = "description", Namespace = "")]
      [System.Xml.Serialization.SoapElementAttribute(ElementName = "description")]
      public string Description
      {
          get
          {
              return this._description;
          }
          set
          {
              this._description = value;
          }
      }
      /// &lt;summary&gt;
      ///  (no documentation provided)
      /// &lt;/summary&gt;
      [System.Xml.Serialization.XmlElementAttribute(ElementName = "displayName", Namespace = "")]
      [System.Xml.Serialization.SoapElementAttribute(ElementName = "displayName")]
      public string DisplayName
      {
          get
          {
              return this._displayName;
          }
          set
          {
              this._displayName = value;
          }
      }
      /// &lt;summary&gt;
      ///  (no documentation provided)
      /// &lt;/summary&gt;
      [System.Xml.Serialization.XmlElementAttribute(ElementName = "docId", Namespace = "")]
      [System.Xml.Serialization.SoapElementAttribute(ElementName = "docId")]
      public string DocId
      {
          get
          {
              return this._docId;
          }
          set
          {
              this._docId = value;
          }
      }
      /// &lt;summary&gt;
      ///  (no documentation provided)
      /// &lt;/summary&gt;
      [System.Xml.Serialization.XmlElementAttribute(ElementName = "version", Namespace = "")]
      [System.Xml.Serialization.SoapElementAttribute(ElementName = "version")]
      public Com.Honeywell.Hxps.Sdk.Model.Impl.VersionImpl Version
      {
          get
          {
              return this._version;
          }
          set
          {
              this._version = value;
          }
      }
      /// &lt;summary&gt;
      ///  (no documentation provided)
      /// &lt;/summary&gt;
      [System.Xml.Serialization.XmlElementAttribute(ElementName = "fields", Namespace = "")]
      [System.Xml.Serialization.SoapElementAttribute(ElementName = "fields")]
      public object Fields
      {
          get
          {
              return this._fields;
          }
          set
          {
              this._fields = value;
          }
      }
      /// &lt;summary&gt;
      ///  (no documentation provided)
      /// &lt;/summary&gt;
      [System.Xml.Serialization.XmlElementAttribute(ElementName = "revision", Namespace = "")]
      [System.Xml.Serialization.SoapElementAttribute(ElementName = "revision")]
      public string Revision
      {
          get
          {
              return this._revision;
          }
          set
          {
              this._revision = value;
          }
      }
      /// &lt;summary&gt;
      ///  (no documentation provided)
      /// &lt;/summary&gt;
      [System.Xml.Serialization.XmlElementAttribute(ElementName = "id", Namespace = "")]
      [System.Xml.Serialization.SoapElementAttribute(ElementName = "id")]
      public string Id
      {
          get
          {
              return this._id;
          }
          set
          {
              this._id = value;
          }
      }
  }
  }
  </code></pre>
  
  <p>In my main program, I get an array of xmlNodes when I try </p>
  
  <pre><code>Array fields = (Array)doc.Fields;
  </code></pre>
  
  <p>In the server side java REST service implementation, fields is actually a arraylist which will contain instances of three implementations of an interface. (List may contain ScalarFieldImpl or ArrayFieldImpl which are custom business objects). </p>
  
  <p>I want to deserialize this xml fields into ScalarFieldImpl or ArrayFieldImpl using XmlSerializer. I want to know whether it is possible? If so, how do I do that?</p>