title: Error while deserializing xml string into object using XMLSerializer in C#
body: <p>Here is my DTO</p>
  
  <pre><code>[XmlTypeAttribute(TypeName="XAttributes")]
  public class XAttributes
  {
      [XmlArray(ElementName="Attributes")]
      [XmlArrayItem(ElementName="Attribute")]
      public List&lt;Attribute&gt; Attributes { get; set; }    
      public XAttributes()
      {
          Attributes = new List&lt;Attribute&gt;();
      }
  }
  public class Attribute
  {      
      [XmlElement(ElementName = "Name")]
      public string Name { get; set; }
  
      [XmlElement(ElementName = "Value")]
      public string Value { get; set; }      
  
      [XmlElement(ElementName = "ValueType")]
      public ValueType ValueType {get; set; }
  
      [XmlArray(ElementName="Children" )]
      public List&lt;Attribute&gt; Children { get; set; }
  }
  </code></pre>
  
  <p>and here is my deserializing code</p>
  
  <pre><code>  public static T ToObject&lt;T&gt;(this string XMLData)
      {
          var s = new XmlSerializer(typeof(T));
          object obj=null;
          using (var sr = new StringReader(XMLData))
          {
              obj = s.Deserialize(sr);
          }
          return (T)obj;
      }
  </code></pre>
  
  <p>and here is the code i call to deserialize it</p>
  
  <pre><code>string attr = @"&lt;XAttributes&gt;&lt;Attributes&gt;                          
                          &lt;Attribute&gt;
                          &lt;Name&gt;Test&lt;/Name&gt;
                          &lt;Value&gt;TestVlau&lt;/Value&gt;
                          &lt;ValueType&gt;STRING&lt;/ValueType&gt;
                          &lt;Children/&gt;
                          &lt;/Attribute&gt;
                          &lt;Attribute&gt;
                          &lt;Name&gt;Test1&lt;/Name&gt;
                          &lt;Value&gt;TestVlau1&lt;/Value&gt;
                          &lt;ValueType&gt;STRING&lt;/ValueType&gt;
                          &lt;Children/&gt;
                          &lt;/Attribute&gt;
                          &lt;/Attributes&gt;&lt;XAttributes&gt;";
  
          var attribute = attr.ToObject&lt;XAttributes&gt;();
  </code></pre>
  
  <p>i get error as </p>
  
  <pre><code>There is an error in XML document (14, 55).
  </code></pre>
  
  <p>at the line</p>
  
  <pre><code> obj = s.Deserialize(sr);
  </code></pre>
  
  <p>Any help is greatly appreciated.</p>
  
  <p>Thanks.</p>