title: Polymorphic XML Serialization/DeSerialization to C# objects for varying list of nodes
body: <p>I have an XML file like this</p>
  
  <pre><code>&lt;xml&gt;
      &lt;nodes&gt;
          &lt;text/&gt;
          &lt;img/&gt;
          &lt;text/&gt;
      &lt;/nodes&gt;
  &lt;/xml&gt;
  </code></pre>
  
  <p>I want to map C# objects to this, I know how to use XmlArrayItem but only incase where there is only one item type in array. I was thinking how to do it using a base class for img and text nodes. But can anyone show my code for C# attributes that I can use to auto DeSerialize this xml into C# objects. Using LINQ is not needed.</p>
  
  <p>Here is how I plan to do but its not working:</p>
  
  <pre><code>[Serializable]
  [XmlRoot ( "textfile" )]
  public class TextFile
  {
  
      [XmlArray ( "nodes" )]
      [XmlArrayItem ( "text", typeof(NodeText)), XmlArrayItem ( "img", typeof(NodeImg) )]
      public List&lt;NodeBase Nodes
      {
          get;
          set;
      }
  
  
  }
  
  [Serializable]
  public class NodeBase
  {
  }
  
  [Serializable]
  public class NodeText : NodeBase
  {
  
  
  [XmlText]
  public String CDataContent
  {
          get;
          set;
      }
  }
  
  [Serializable]
  public class NodeImg : NodeBase
  {
  
      [XmlAttribute ( "width" )]
      public Int32 Width
      {
          get;
          set;
      }
  
      [XmlAttribute ( "height" )]
      public Int32 Height
      {
          get;
          set;
      }
  
      [XmlAttribute ( "src" )]
      public String SourceImgStr
      {
          get;
          set;
      }
  }
  </code></pre>