您好,欢迎来到[编程问答]网站首页   源码下载   电子书籍   软件下载   专题
当前位置:首页 >> 编程问答 >> .NET >> 用过socket收到的字节流能直接转换成xdocument类型吗

用过socket收到的字节流能直接转换成xdocument类型吗

来源:网络整理     时间:2016/5/15 6:14:30     关键词:document,Socket

关于网友提出的“用过socket收到的字节流能直接转换成xdocument类型吗”问题疑问,本网通过在网上对“用过socket收到的字节流能直接转换成xdocument类型吗”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题:用过socket收到的字节流能直接转换成xdocument类型吗
描述:

用过socket收到的字节流能直接转换成xdocument类型吗


解决方案1:

直接用 XmlTextReader(Stream) 读字节流就可以了,不需要先转字符流再转XML。

解决方案2:

需要将字节流转换成字符流

using (StreamReader sr = new StreamReader("TestFile.txt"))
            {
                string line;
                // Read and display lines from the file until the end of
                // the file is reached.
                while ((line = sr.ReadLine()) != null)
                {
                    Console.WriteLine(line);
                }
            }

解决方案3:

不能,得先转换成TextReader

再用XDocument.Load方法读取


以上介绍了“用过socket收到的字节流能直接转换成xdocument类型吗”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/1082257.html

相关图片

相关文章