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.
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
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
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
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
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
using (var xmlStream = new MemoryStream(fileContent))
using (var xmlReader = new XmlTextReader(xmlStream))
{
xml = XDocument.Load(xmlReader);
}
That combination works -- Greg
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