首页 > 解决方案 > XMLDocument 加载(XmlReader)与加载(流)

问题描述

我正在使用带有输入参数的 XMLDocument 加载函数作为流 xml 数据。我看到这样做CA3075的违规行为。对于字符串数据,建议创建 XmlReader 对象并将其传递给 XMLDocument Load 函数,并在参数中将 XMLResolver 值设置为 null。

    System.IO.StringReader sreader = new System.IO.StringReader(xml);
    XmlReader reader = XmlReader.Create(sreader, new XmlReaderSettings() { XmlResolver = null });
    doc.Load(reader);

参考:https ://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca3075#solution-3

我想了解使用 XMLReader 与流作为参数有什么区别?

标签: c#xmlxmldocumentxmlreader

解决方案


推荐阅读