Re: Buffer to XML problem

2014-02-05 Thread piers.williams
Once loaded into a .net string, it is Unicode. So then the encoding stated in the Xml preamble (UTF-8) is then wrong. By passing a stream to the XmlDocument (directly, or via XmlTextReader(stream)) then the Encoding associated with the stream (which is sniffed from the BOM) is passed as well.

Re: Buffer to XML problem

2014-02-05 Thread Greg Keogh
Once loaded into a .net string, it is Unicode. [cut] That's the rub, but it's so obvious you can forget it. The problem exists in the reverse direction because you will see countless people in web searches asking why is my saved XML coming out as UTF-16?. It turns out they're using a

Re: Buffer to XML problem

2014-01-31 Thread Davy Jones
Sorry about the terse message last time. Either the text reader or the stream reader takes an encoding, you have to specify it the same as the encoding in the XML document. If you pass XML to a SQL parameter you use Unicode (UTF-16) otherwise always explicitly use the same encoding, there are

Re: Buffer to XML problem

2014-01-30 Thread Tristan Reeves
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

Re: Buffer to XML problem

2014-01-30 Thread Jano Petras
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

Re: Buffer to XML problem

2014-01-30 Thread Davy Jones
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

Re: Buffer to XML problem

2014-01-30 Thread Greg Keogh
using (var xmlStream = new MemoryStream(fileContent)) using (var xmlReader = new XmlTextReader(xmlStream)) { xml = XDocument.Load(xmlReader); } That combination works -- Greg

Re: Buffer to XML problem

2014-01-30 Thread Greg Keogh
You need to specify the encoding. Constructing a UTF8Encoding with BOM = true has no effect, as I was soon reminded that this flag is only for emitting a BOM -- Greg