【发布时间】:2018-02-16 22:28:02
【问题描述】:
如何在 .NET Core 1.1.2 中针对 XSD 架构验证 XML?我找到了这个ms docs,但我不能将它与 .NET core 1.1.2 一起使用
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Schema;
namespace MyNameSpace
{
public static class XmlValidation
{
public static void Validate(string schema, string xml)
{
XmlReaderSettings schemaSettings = new XmlReaderSettings();
schemaSettings.Schemas.Add(schema);
schemaSettings.ValidationType = ValidationType.Schema;
schemaSettings.ValidationEventHandler += new ValidationEventHandler(ValidationEventHandler);
XmlReader reader = XmlReader.Create(xml, schemaSettings);
while (reader.Read()) { }
}
static void ValidationEventHandler(object sender, ValidationEventArgs e)
{
// do something
}
}
}
我遇到错误
找不到类型或命名空间名称“ValidationEventHandler”
找不到类型或命名空间名称“ValidationEventArgs”
当前上下文域中不存在名称“ValidationType”
“XmlReaderSettings”不包含“架构”的定义,并且 没有扩展方法'Schemas'接受类型的第一个参数 可以找到“XmlReaderSettings”(您是否缺少 using 指令 还是程序集参考?)
我在这里缺少任何 Nuget 包还是 .NET Core 1.1 甚至不支持 xml 验证?
【问题讨论】:
标签: .net-core asp.net-core-1.0 coreclr system.xml