title: Adding a namespace prefix to an XmlRoot Attribute
body: <p>:riI am working on a .Net web api, we have a base class that handles all responses from our api. This class will always be returned as the root of the request, with whatever data the user requested inside it.</p>
  
  <p>So the user will always receive a response along the lines of:</p>
  
  <pre><code>&lt;Content xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns="http://www.example.com/schemas/TestNamespace/Interface6/Schema.xsd"&gt;
          &lt;Item&gt;Information Here&lt;/Item&gt;
  &lt;/Content&gt;
  </code></pre>
  
  <p>I have the following code which returns the above fine:</p>
  
  <pre><code>[XmlRoot(ElementName = "Content", Namespace = "http://www.example.com/schemas/TestNamespace/Interface6/Schema.xsd")]
  public class MyResponse&lt;T&gt; : IMyResponse&lt;T&gt;
      where T : class
  {//rest of class}
  </code></pre>
  
  <p>So no matter what the root tag of the return data is, it will always be changed to "Content". So if T in my code is a PersonList, itll be changed to "Content" in the XML. This is to provide consistency in our responses.</p>
  
  <p>Now I need to add a prefix to the tag. "ri:" So the response received will be:</p>
  
  <pre><code>&lt;ri:Content xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:ri="http://www.example.com/schemas/TestNamespace/Interface6/Schema.xsd"&gt;
          &lt;Item&gt;Information Here&lt;/Item&gt;
  &lt;/ri:Content&gt;
  </code></pre>
  
  <p>Every question close to what i require has provided solutions to add the prefix in code. </p>
  
  <p>I want to know if there is a way to do this using the attribute ?</p>
  
  <p><a href="https://stackoverflow.com/questions/20122557/how-to-add-prefix-in-front-of-xml-element-using-attribute-in-c-sharp">Here is a similar question that was never answered</a></p>
  
  <p>Edit: Adding ri: to the ElementName of the XmlRoot Attribute does not work. </p>
  
  <pre><code>[XmlRoot(ElementName = "ri:Content", Namespace = "http://www.example.com/schemas/TestNamespace/Interface6/Schema.xsd")]
  </code></pre>
  
  <p>Returns as:</p>
  
  <pre><code>&lt;ri_x003A_Content xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xmlns="http://www.example.com/schemas/TestNamespace/Interface6/Schema.xsd"&gt;
              &lt;Item&gt;Information Here&lt;/Item&gt;
      &lt;/ri_x003A_Content&gt;
  </code></pre>