c# Detect xml encoding from Byte Array?

前端 未结 4 1065
日久生厌
日久生厌 2020-12-17 01:38

Well i have a byte array, and i know its a xml serilized object in the byte array is there any way to get the encoding from it?

Im not going to deserilize it but im

4条回答
  •  孤街浪徒
    2020-12-17 02:19

    A solution similar to this question could solve this by using a Stream over the byte array. Then you won't have to fiddle at the byte level. Like this:

    Encoding encoding;
    using (var stream = new MemoryStream(bytes))
    {
        using (var xmlreader = new XmlTextReader(stream))
        {
            xmlreader.MoveToContent();
            encoding = xmlreader.Encoding;
        }
    }
    

提交回复
热议问题