title: Add xml-stylesheet processing instruction just before root element
body: <p>I have an XML document that is generated from database information. I also have a separate XMLT file. I need to use VB.NET to insert the XSL link into the XML document. I am getting it inserted, but it's inserting into the wrong place. I need it in the header but it's putting it after the root node.</p>
  
  <p>Here's the code I'm using to insert the xml-stylsheet processing instruction:</p>
  
  <pre><code>Dim fiFilePath As String = Me.CSFileName
  Dim xmlCs As XmlDocument = Nothing
  Try
      xmlCs = New XmlDocument()
      xmlCs.Load(fiFilePath)
      ' update the XSLT path as per the 'newStyleSheetPath' argument
      xmlCs.DocumentElement.PrependChild(xmlCs.CreateProcessingInstruction("xml-stylesheet", String.Format("type={0}text/xsl{1} href={2}{3}{4}", Chr(34), Chr(34), Chr(34), newStylesheetPath, Chr(34))))
      'Save the created document
      xmlCs.Save(fiFilePath)
  Catch ex As Exception
      xmlCs = Nothing
      fiFilePath = Nothing
      Throw ex
  End Try
  </code></pre>
  
  <p>This is what that code is outputting:</p>
  
  <pre><code>&lt;DocumentRoot&gt;
    &lt;?xml-stylesheet type="text/xsl" href="APSCS.xsl"?&gt;
    &lt;realmCode code="US" /&gt;
  </code></pre>
  
  <p>But it needs to be:</p>
  
  <pre><code>&lt;?xml-stylesheet type="text/xsl" href="APSCS.xsl"?&gt;
  &lt;DocumentRoot&gt;
    &lt;realmCode code="US" /&gt;
  </code></pre>
  
  <p>This is all part of an export where the XSLT is packaged with the XML, so if someone opens the XML, it appears in the browser using the XSLT file sent with it.</p>