代码之家  ›  专栏  ›  技术社区  ›  Piotr Perak

.net核心中的xsd验证[重复]

  •  0
  • Piotr Perak  · 技术社区  · 7 年前

    如何根据.NETCore1.1.2中的XSD模式验证XML?我找到这个了 ms docs 但我不能将它与.NETCore1.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”和“Schemas”的定义 没有接受类型为的第一个参数的扩展方法“Schemas”

    我是否缺少任何Nuget包或者.NETCore1.1甚至不支持xml验证?

    0 回复  |  直到 8 年前
        1
  •  1
  •   omajid    8 年前
    推荐文章