title: Write XML attributes and namespace declarations in specific order in C#?
body: <p>I've tried this for a while, and am having trouble writing an XML start element in C# with XmlWriter.</p>
  <p>The output line is supposed to look like:
  &lt;s:Scenario xmlns:s=&quot;./scenarios&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;</p>
  <p>But the best I've been able to get has been:
  &lt;s:Scenario xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:s=&quot;./scenarios&quot; /&gt;</p>
  <p>with the following code:</p>
  <pre><code>xmlWriter.WriteStartElement(&quot;s&quot;, &quot;Scenario&quot;, &quot;./scenarios&quot;);        
  xmlWriter.WriteAttributeString(&quot;xmlns&quot;, &quot;xsi&quot;, null, &quot;http://www.w3.org/2001/XMLSchema-instance&quot;);
  </code></pre>
  <p>Is there a better way to write this line? WriteRaw will not work, because this is supposed to be the first line following <code>xmlWriter.WriteStartDocument();</code>, and it ends up throwing an InvalidOperationException: &quot;Token StartElement in state EndRootElement would result in an invalid XML document. (...).&quot;</p>
  <p>Let me know if you need more context! Thanks in advance.</p>