久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

      <legend id='sTnZQ'><style id='sTnZQ'><dir id='sTnZQ'><q id='sTnZQ'></q></dir></style></legend>

    1. <small id='sTnZQ'></small><noframes id='sTnZQ'>

        <i id='sTnZQ'><tr id='sTnZQ'><dt id='sTnZQ'><q id='sTnZQ'><span id='sTnZQ'><b id='sTnZQ'><form id='sTnZQ'><ins id='sTnZQ'></ins><ul id='sTnZQ'></ul><sub id='sTnZQ'></sub></form><legend id='sTnZQ'></legend><bdo id='sTnZQ'><pre id='sTnZQ'><center id='sTnZQ'></center></pre></bdo></b><th id='sTnZQ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='sTnZQ'><tfoot id='sTnZQ'></tfoot><dl id='sTnZQ'><fieldset id='sTnZQ'></fieldset></dl></div>
      1. 通過單一方法針對 XSD 驗證 XML

        Validate XML against XSD in a single method(通過單一方法針對 XSD 驗證 XML)

            <legend id='2Z6EG'><style id='2Z6EG'><dir id='2Z6EG'><q id='2Z6EG'></q></dir></style></legend>
              <tbody id='2Z6EG'></tbody>

                <small id='2Z6EG'></small><noframes id='2Z6EG'>

                  <bdo id='2Z6EG'></bdo><ul id='2Z6EG'></ul>
                • <i id='2Z6EG'><tr id='2Z6EG'><dt id='2Z6EG'><q id='2Z6EG'><span id='2Z6EG'><b id='2Z6EG'><form id='2Z6EG'><ins id='2Z6EG'></ins><ul id='2Z6EG'></ul><sub id='2Z6EG'></sub></form><legend id='2Z6EG'></legend><bdo id='2Z6EG'><pre id='2Z6EG'><center id='2Z6EG'></center></pre></bdo></b><th id='2Z6EG'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='2Z6EG'><tfoot id='2Z6EG'></tfoot><dl id='2Z6EG'><fieldset id='2Z6EG'></fieldset></dl></div>
                • <tfoot id='2Z6EG'></tfoot>
                • 本文介紹了通過單一方法針對 XSD 驗證 XML的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我需要實現一個 C# 方法,該方法需要針對外部 XSD 驗證 XML 并返回一個布爾結果,指示它是否格式正確.

                  I need to implement a C# method that needs to validate an XML against an external XSD and return a Boolean result indicating whether it was well formed or not.

                  public static bool IsValidXml(string xmlFilePath, string xsdFilePath);
                  

                  我知道如何使用回調進行驗證.我想知道它是否可以在一個方法中完成,而不使用回調.我需要這個純粹是為了美觀:我需要驗證多達幾十種類型的 XML 文檔,所以我想做如下簡單的事情.

                  I know how to validate using a callback. I would like to know if it can be done in a single method, without using a callback. I need this purely for cosmetic purposes: I need to validate up to a few dozen types of XML documents so I would like to make is something as simple as below.

                  if(!XmlManager.IsValidXml(
                      @"ProjectTypesProjectType17.xml",
                      @"SchemasProject.xsd"))
                  {
                       throw new XmlFormatException(
                           string.Format(
                               "Xml '{0}' is invalid.", 
                               xmlFilePath));
                  }
                  

                  推薦答案

                  根據您是否要對非異常事件使用異常,我可以想到幾個選項.

                  There are a couple of options I can think of depending on whether or not you want to use exceptions for non-exceptional events.

                  如果你傳遞一個 null 作為驗證回調委托,如果 XML 格式錯誤,大多數內置驗證方法都會拋出異常,因此你可以簡單地捕獲異常并返回 true/false視情況而定.

                  If you pass a null as the validation callback delegate, most of the built-in validation methods will throw an exception if the XML is badly formed, so you can simply catch the exception and return true/false depending on the situation.

                  public static bool IsValidXml(string xmlFilePath, string xsdFilePath, XNamespace namespaceName)
                  {
                      var xdoc = XDocument.Load(xmlFilePath);
                      var schemas = new XmlSchemaSet();
                      schemas.Add(namespaceName, xsdFilePath);
                  
                      try
                      {
                          xdoc.Validate(schemas, null);
                      }
                      catch (XmlSchemaValidationException)
                      {
                          return false;
                      }
                  
                      return true;
                  }
                  

                  想到的另一個選項是在不使用回調 標準的情況下突破的限制.除了傳遞預定義的回調方法,您還可以傳遞一個匿名方法并使用它來設置 true/false 返回值.

                  The other option that comes to mind pushes the limits of your without using a callback criterion. Instead of passing a pre-defined callback method, you could instead pass an anonymous method and use it to set a true/false return value.

                  public static bool IsValidXml(string xmlFilePath, string xsdFilePath, XNamespace namespaceName)
                  {
                      var xdoc = XDocument.Load(xmlFilePath);
                      var schemas = new XmlSchemaSet();
                      schemas.Add(namespaceName, xsdFilePath);
                  
                      Boolean result = true;
                      xdoc.Validate(schemas, (sender, e) =>
                           {
                               result = false;
                           });
                  
                      return result;
                  }
                  

                  這篇關于通過單一方法針對 XSD 驗證 XML的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  What are good algorithms for vehicle license plate detection?(車牌檢測有哪些好的算法?)
                  onClick event for Image in Unity(Unity中圖像的onClick事件)
                  Running Total C#(運行總 C#)
                  Deleting a directory when clicked on a hyperlink with JAvascript.ASP.NET C#(單擊帶有 JAvascript.ASP.NET C# 的超鏈接時刪除目錄)
                  asp.net listview highlight row on click(asp.net listview 在單擊時突出顯示行)
                  Calling A Button OnClick from a function(從函數調用按鈕 OnClick)
                  • <small id='BSvaW'></small><noframes id='BSvaW'>

                      <bdo id='BSvaW'></bdo><ul id='BSvaW'></ul>

                        <legend id='BSvaW'><style id='BSvaW'><dir id='BSvaW'><q id='BSvaW'></q></dir></style></legend>
                          1. <i id='BSvaW'><tr id='BSvaW'><dt id='BSvaW'><q id='BSvaW'><span id='BSvaW'><b id='BSvaW'><form id='BSvaW'><ins id='BSvaW'></ins><ul id='BSvaW'></ul><sub id='BSvaW'></sub></form><legend id='BSvaW'></legend><bdo id='BSvaW'><pre id='BSvaW'><center id='BSvaW'></center></pre></bdo></b><th id='BSvaW'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='BSvaW'><tfoot id='BSvaW'></tfoot><dl id='BSvaW'><fieldset id='BSvaW'></fieldset></dl></div>
                            <tfoot id='BSvaW'></tfoot>

                              <tbody id='BSvaW'></tbody>

                            主站蜘蛛池模板: 亚洲精品视频导航 | 亚洲精品乱码久久久久久9色 | 91精品国产综合久久福利软件 | 国产成人免费视频网站高清观看视频 | 欧美精品一区二区三区四区五区 | 天堂免费 | 国产亚洲精品美女久久久久久久久久 | 精品国产亚洲一区二区三区大结局 | 免费一区二区三区在线视频 | 国产高清久久久 | 婷婷在线免费 | 黄色毛片免费 | 四虎影院在线观看av | 国产欧美综合在线 | 在线免费观看视频你懂的 | av二区三区 | 亚洲男人的天堂网站 | 一区二区三区国产精品 | 亚洲人成在线播放 | 最新国产精品 | 91视频在线看 | 欧美激情亚洲激情 | 国产欧美久久精品 | 欧美bondage紧缚视频 | 国产激情91久久精品导航 | 91社区在线高清 | 人人干人人超 | 国产情侣激情 | 成人一区二区视频 | 国产在线播放一区二区三区 | 宅男噜噜噜66一区二区 | 国产a级毛毛片 | 亚洲免费久久久 | 影音先锋欧美资源 | 久久精品小短片 | 最新国产精品精品视频 | 美女视频黄色片 | 日韩精品成人 | 亚洲三区在线观看 | 91在线导航 | 午夜精品 |