According to
http://stackoverflow.com/questions/2111586/parsing-xml-string-to-an-xml-document-fails-if-the-string-begins-with-xml
this could be a problem with the "pre-amble". One reply says to use
using (var xmlStream = new MemoryStream(fileContent))
using (var xmlReader = new XmlTextReader(xmlStream))
{
xml = XDocument.Load(xmlReader);
}
Hope that helps,
Tristan.
On Fri, Jan 31, 2014 at 8:09 AM, Greg Keogh <[email protected]> wrote:
> Folks, I can't convert to byte buffer to an XML document. The input buffer
> contains a serialized string with a UTF8 BOM which starts like this:
>
> EFBBBF3C3F786D6C2076657273696F6E3D22312E302220656E636F64696E673D227574662D38223F3E0D0A3C5573
> [cut]
> . . . < ? x m l v e r s i o n = " 1 . 0 " e n c o d i n g = " u t f - 8
> " ? > . . < U s
>
> So I do this:
>
> string xml = Encoding.UTF8.GetString(buffer);
> var doc = XDocument.Parse(xml);
>
> However the Parse dies with "System.Xml.XmlException : Data at the root
> level is invalid. Line 1, position 1."
>
> What am I missing here?
>
> Greg K