c# - 系统UriFormatException : 'Invalid URI: The Uri scheme is too long.'

标签 c# xml xmldocument

我正在开发一个小项目,我正在尝试从 websocket 读取响应并尝试将其加载到 xmlDoc 中以进行进一步操作。

以下是我的代码片段,其中我得到“System.UriFormatException”。响应是 XMLType

        UTF8Encoding encoder = new UTF8Encoding();
        byte[] buffer;

        buffer = encoder.GetBytes("<XML Response from a websocket>");

        string xml = Encoding.UTF8.GetString(buffer);

        XmlDocument xmlDoc = new XmlDocument();

        xmlDoc.Load(xml);

有什么方法可以克服异常,或者我在这段代码中做错了什么。

最佳答案

让我们访问文档

XmlDocument.Load(String)

Loads the XML document from the specified URL.

xmlDoc.Load(xml);

xml 不是 Url

您最有可能寻找的是

XmlDocument.LoadXml(String) Method

Loads the XML document from the specified string.

关于c# - 系统UriFormatException : 'Invalid URI: The Uri scheme is too long.' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54782592/

相关文章:

c# - Owin 中间件在服务器上导致 404

c# - 右对齐 datagridview 中的列不起作用

c# - XmlDocument.Load : Could not create SSL/TLS secure channel

.net - XmlDocument 不保存标签之间的空格

.net - XmlDocument.ImportNode 的 XDocument 等效项是什么?

c# - 我如何通知容器对象一个属性已经从被改变的对象中改变了?

c# - Crystal 报表 ExportToDisk 消耗大量时间

python - 在 Python : how to know how much of the input file has been read? 中使用 lxml 迭代 XML

c# - 如何测试 XML 字符串在 .net 中的格式是否正确

javascript - 如何在js中添加target=blank?