.net core 如何在.NETCore1.1.2中验证XML
如何根据.NETCore1.1.2中的XSD模式验证XML?我找到了这个,但无法与.NET core 1.1.2一起使用.net core 如何在.NETCore1.1.2中验证XML,.net-core,asp.net-core-1.0,coreclr,system.xml,.net Core,Asp.net Core 1.0,Coreclr,System.xml,如何根据.NETCore1.1.2中的XSD模式验证XML?我找到了这个,但无法与.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 {
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验证?它不支持。在
事件
下没有验证EventHandler
。存在的位置。那么我们如何验证.net core 1.1.2中的Xml?@LP13:为什么不升级到.net core 2.0?。从.NETCore1.1.2升级到2.0非常简单,这就是我最终要做的。