title: Unexpected XML Declaration. XML Declaration must be the first node in the document and no whitespace characters are allowed to appear before it linit
body: <p>I'm having some trouble with xml declaration and encoding. I have some excel files which have an issue with the encoding/declaration. I have no control over how the files are created. They are received directly from a client</p>
  <p>I'm trying to using C# to rewrite the declaration and insert a the first node. However I keep running into the same response. I understand the error message is clear, what's not clear to me is why the newly created declaration is not solving this issue.</p>
  <p>I assumed because it reads as the first child in the node which I checked and by prepending it would solve my issue but it hasn't. I've been stuck on this for quite a while. Any push in the right direction would greatly appreciated.</p>
  <p>Error occurs on the last line --&gt; var worksheets = xlPack.Workbook.Worksheets;</p>
  <p>Actual error message --&gt;</p>
  <blockquote>
  <p>Unexpected XML Declaration. XML Declaration must be the first node in the document and no whitespace characters are allowed to appear before it line 2 position 1228.</p>
  </blockquote>
  <p>sample xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
  &lt;p:properties xmlns:p=http://schemas.microsoft.com/office/2006/metadata/properties xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:pc=http://schemas.microsoft.com/office/infopath/2007/PartnerControls&gt;
  &lt;documentManagement /&gt;
  &lt;/p:properties&gt;
  </code></pre>
  <pre><code>using (StreamWriter sw = new StreamWriter(filePath + exportFileName))
  
                  {
  
                      using (ExcelPackage xlPack = new ExcelPackage(new FileInfo(importFile)))
  
                      {
  
                          var xmlDec = xlPack.Workbook.WorkbookXml.CreateXmlDeclaration(&quot;1.0&quot;, null, null);
  
                          var root = xlPack.Workbook.WorkbookXml.DocumentElement;
  
                          var roottwo = xlPack.Workbook.WorkbookXml;
  
                          var originalXMLDec = roottwo.FirstChild;
  
                          var originalXMLDecread = roottwo.FirstChild.Value;
  
                          var firstChildCheck = roottwo.FirstChild.NodeType;
  
                          var checkNodeType = xmlDec.NodeType;
  
                          roottwo.RemoveChild(originalXMLDec);
  
                          roottwo.PrependChild(xmlDec);
  
                          var rootTwo = root.InnerXml;
  
                    var worksheets = xlPack.Workbook.Worksheets;
  </code></pre>