开发者

Given an XML stream how can one know whether it is a binary XML or non binary XML stream?

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开发者_Go百科. 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜