tags:

views:

54

answers:

1

Dear ladies and sirs.

I have a stream which contains some XML. The XML may either be encoded using binary XML writer (for instance obtained from XmlDictionaryWriter.CreateBinaryWriter) or non binary XML writer (like as in XmlWriter.Create).

I wish to know which reader to use - the one from XmlDictionaryReader.CreateBinaryReader or the one from XmlReader.Create. Of course, I can assume that the XML is non binary and then try and fallback to binary. This is what I do today. But I do not like this approach. I wonder if there is an API, which can guide me in the first place which reader to select.

Thanks.

A: 

You could check the data (or the first 100 characters for example) and see if there are any invalid XML characters and if you don't find any then use the current solution - try XmlReader.Create first and fall back to XmlDictionaryReader.CreateBinaryReader.

Pent Ploompuu
Not good. The first byte is 64 and the second is 16. The stream is binary XML.
mark
I added a more correct solution: if there are no invalid XML characters then it's most likely non-binary XML.
Pent Ploompuu