0

So basically I have an spreadsheetwriter class which has WriteToStream() method which takes an spreadsheet as input and convert that spreadsheet to stream. Now what I am trying to do is to convert the stream into xml format so that at unit testing I am able to compare it. But I have tried many thing but always it shows the following error. System.Xml.XmlException: 'Data at the root level is invalid. Line 1, position 1.'

Stream stream = SpreadsheetWriter.WriteToStream(sheet);
stream.Seek(0, SeekOrigin.Begin);
XmlDocument xmlDocument = new();
xmlDocument.Load(stream);
xmlDocument.Save(@"..\Demo.xml");


  
VenomAk
  • 3
  • 2
  • It's not clear exactly what `SpreadsheetWriter` is, but at a guess it's failing because a spreadsheet is not XML. If it's e.g. Excel OpenXML format, it'll be a zip file full of lots of different XML files. – Charles Mager Mar 11 '22 at 09:28
  • Does this answer your question? [xml.LoadData - Data at the root level is invalid. Line 1, position 1](https://stackoverflow.com/questions/17795167/xml-loaddata-data-at-the-root-level-is-invalid-line-1-position-1) – Jiale Xue - MSFT Mar 11 '22 at 09:44

0 Answers0