title: Changing type of element in XML Serialization
body: <p>I am having huge problems with XML serialization. I have two classes, both need to be serializeable. In the inherited class, I would like to change the serialization behavior, so that a string property gets serialized as complex type.</p>
  
  <pre><code>public class Animal
  {
      [XmlElement(ElementName = "NAME")]
      public string Name { get; set; }
      public virtual bool ShouldSerializeName() { return true; }
  }
  
  public class Cat : Animal
  {
      public override bool ShouldSerializeName() { return false; }
  
      [XmlElement(ElementName = "NAME")]
      public NameAndType Name2 { get; set; }
  }
  
  public class NameAndType
  {
      public string Name { get; set; }
      public string Type { get; set; }
  }
  
  ...
  
  var cat = new Cat {Name2 = new NameAndType {Name = "LittleCat"}};
  new XmlSerializer(typeof(Cat)).Serialize(Console.Out, cat);
  </code></pre>
  
  <p>I have tried different approaches, but I didn't find a way to change how the  <code>NAME</code> element get's serialized.
  With the example above, I get the error message:</p>
  
  <p><code>The XML element 'NAME' from namespace '' is already present in the current scope. Use XML attributes to specify another XML name or namespace for the element.</code></p>