<i id='kZFpO'><tr id='kZFpO'><dt id='kZFpO'><q id='kZFpO'><span id='kZFpO'><b id='kZFpO'><form id='kZFpO'><ins id='kZFpO'></ins><ul id='kZFpO'></ul><sub id='kZFpO'></sub></form><legend id='kZFpO'></legend><bdo id='kZFpO'><pre id='kZFpO'><center id='kZFpO'></center></pre></bdo></b><th id='kZFpO'></th></span></q></dt></tr></i><div id='kZFpO'><tfoot id='kZFpO'></tfoot><dl id='kZFpO'><fieldset id='kZFpO'></fieldset></dl></div>
  • <small id='kZFpO'></small><noframes id='kZFpO'>

      <legend id='kZFpO'><style id='kZFpO'><dir id='kZFpO'><q id='kZFpO'></q></dir></style></legend>
        <bdo id='kZFpO'></bdo><ul id='kZFpO'></ul>
    1. <tfoot id='kZFpO'></tfoot>

        可以在运行时使用代码针对 xsd 验证 xml 吗?

        时间:2023-06-04
              <bdo id='xODBh'></bdo><ul id='xODBh'></ul>

              <small id='xODBh'></small><noframes id='xODBh'>

                  <tfoot id='xODBh'></tfoot>
                    <tbody id='xODBh'></tbody>
                  <legend id='xODBh'><style id='xODBh'><dir id='xODBh'><q id='xODBh'></q></dir></style></legend>
                  <i id='xODBh'><tr id='xODBh'><dt id='xODBh'><q id='xODBh'><span id='xODBh'><b id='xODBh'><form id='xODBh'><ins id='xODBh'></ins><ul id='xODBh'></ul><sub id='xODBh'></sub></form><legend id='xODBh'></legend><bdo id='xODBh'><pre id='xODBh'><center id='xODBh'></center></pre></bdo></b><th id='xODBh'></th></span></q></dt></tr></i><div id='xODBh'><tfoot id='xODBh'></tfoot><dl id='xODBh'><fieldset id='xODBh'></fieldset></dl></div>

                1. 本文介绍了可以在运行时使用代码针对 xsd 验证 xml 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我有在运行时读入的 xml 文件,是否可以在运行时针对 xsd 文件验证 xml?使用c#

                  I have xml files that I read in at runtime, is is possible to validate the xml against an xsd file at runtime? using c#

                  推荐答案

                  试试这个:

                  public void ValidateXmlDocument(
                      XmlReader documentToValidate, string schemaPath)
                  {
                      XmlSchema schema;
                      using (var schemaReader = XmlReader.Create(schemaPath))
                      {
                          schema = XmlSchema.Read(schemaReader, ValidationEventHandler);
                      }
                  
                      var schemas = new XmlSchemaSet();
                      schemas.Add(schema);
                  
                      var settings = new XmlReaderSettings();
                      settings.ValidationType = ValidationType.Schema;
                      settings.Schemas = schemas;
                      settings.ValidationFlags =
                          XmlSchemaValidationFlags.ProcessIdentityConstraints |
                          XmlSchemaValidationFlags.ReportValidationWarnings;
                      settings.ValidationEventHandler += ValidationEventHandler;
                  
                      using (var validationReader = XmlReader.Create(documentToValidate, settings))
                      {
                          while (validationReader.Read())
                          {
                          }
                      }
                  }
                  
                  private static void ValidationEventHandler(
                      object sender, ValidationEventArgs args)
                  {
                      if (args.Severity == XmlSeverityType.Error)
                      {
                          throw args.Exception;
                      }
                  
                      Debug.WriteLine(args.Message);
                  }
                  

                  这篇关于可以在运行时使用代码针对 xsd 验证 xml 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:修复:全局元素“配置"已被声明 下一篇:开始使用 .NET 进行 XSD 验证

                  相关文章

                  最新文章

                      <tfoot id='MUtzb'></tfoot>
                      • <bdo id='MUtzb'></bdo><ul id='MUtzb'></ul>

                      <small id='MUtzb'></small><noframes id='MUtzb'>

                      <i id='MUtzb'><tr id='MUtzb'><dt id='MUtzb'><q id='MUtzb'><span id='MUtzb'><b id='MUtzb'><form id='MUtzb'><ins id='MUtzb'></ins><ul id='MUtzb'></ul><sub id='MUtzb'></sub></form><legend id='MUtzb'></legend><bdo id='MUtzb'><pre id='MUtzb'><center id='MUtzb'></center></pre></bdo></b><th id='MUtzb'></th></span></q></dt></tr></i><div id='MUtzb'><tfoot id='MUtzb'></tfoot><dl id='MUtzb'><fieldset id='MUtzb'></fieldset></dl></div>
                      <legend id='MUtzb'><style id='MUtzb'><dir id='MUtzb'><q id='MUtzb'></q></dir></style></legend>