I am processing XBRL files, and ran in to a bunch of them that have a Byte-Order-Mark (BOM) at the start. If I manually remove it, I can process the file without any issue.
I've had several failed attempts to remove the BOM from the start of the XML files that I am reading from.
This is the error message I am receiving:
Data at the root level is invalid. Line 1, position 1.
Originally I was using XDocument.Load(filename)
but this was failing with the same error, so I modified the code after gaining advice from Parsing xml string to an xml document fails if the string begins with <?xml... ?> section without success.
void Main()
{
XDocument doc;
var @filename = @"C:\accounts\toprocess\2008\Prod224_8998_00741575_20080630.xml";
byte[] file = File.ReadAllBytes(filename);
using (MemoryStream memory = new MemoryStream(file))
{
using (XmlTextReader oReader = new XmlTextReader(memory))
{
doc = XDocument.Load(oReader);
}
}
}
The XML file can be found here: http://s000.tinyupload.com/download.php?file_id=92333278767554773703&t=9233327876755477370347742