You need to specify the encoding. Davy
Sent from my starfleet datapad. On 30 janv. 2014, at 22:31, Jano Petras <jano.pet...@gmail.com> wrote: I reckon the BOM neefs to be stripped off becase parse sees it as unicode characters. When dealing with files .net understands BOM and removes it from returned data but it does not expect to see it in string/memory buffer. There are examples on net how to remove it from inmemory buffer so xml parses nicely. On Friday, 31 January 2014, Tristan Reeves <tree...@gmail.com> wrote: > 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 <g...@mira.net> 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 >