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

  • <legend id='GPHMG'><style id='GPHMG'><dir id='GPHMG'><q id='GPHMG'></q></dir></style></legend>

      • <bdo id='GPHMG'></bdo><ul id='GPHMG'></ul>

      <tfoot id='GPHMG'></tfoot>

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

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

      1. 如何解析 XSD 以從 &lt;xsd:simpleType&gt; 獲取信

        How to parse an XSD to get the information from lt;xsd:simpleTypegt; elements using C#?(如何解析 XSD 以從 lt;xsd:simpleTypegt; 獲取信息使用 C# 的元素?)
        <tfoot id='qim93'></tfoot>

          <legend id='qim93'><style id='qim93'><dir id='qim93'><q id='qim93'></q></dir></style></legend>
              <tbody id='qim93'></tbody>
              • <bdo id='qim93'></bdo><ul id='qim93'></ul>

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

                • <small id='qim93'></small><noframes id='qim93'>

                  本文介紹了如何解析 XSD 以從 &lt;xsd:simpleType&gt; 獲取信息使用 C# 的元素?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我有一個具有多種復雜類型和簡單類型的 XSD(文件的一部分如下所示).我需要解析這個文檔以從復雜類型中引用的每個簡單類型中獲取 maxLength.任何人都可以就如何實現這一點提出一些建議嗎?我需要以通用方式實現這一點,所以如果我查詢Setup_Type",它應該給出以下輸出.謝謝!

                  I have an XSD with multiple complex types and simple types (part of the file shown below). I need to parse this document to get maxLength from each of the simpletypes that are referenced in the complex types. Can anyone please throw some advice on how to implement this? I need to implement this in a generic way so if I query on "Setup_Type" it should give the below output. Thank you!

                  NewSetup/Amount = 12(由/"分隔的元素標簽的名稱屬性和嵌套simpleType的maxLength)

                  NewSetup/Amount = 12 (The name attributes from element tags separated by "/" and maxLength from the nested simpleType)

                  新設置/名稱 = 50

                  NewSetup/Name = 50

                  <xsd:complexType name="Setup_Type">
                    <xsd:sequence>
                      <xsd:element name="NewSetup" type="NewSetup_Type" minOccurs="1" maxOccurs="1" />
                    </xsd:sequence>
                  </xsd:complexType>
                  
                  <xsd:complexType name="NewSetup_Type">
                    <xsd:sequence>
                      <xsd:element name="Amount" type="Amount_Type"  minOccurs="1" maxOccurs="1" />
                      <xsd:element name="Name" type="Name_Type"  minOccurs="1" maxOccurs="1" />
                    </xsd:sequence>
                  </xsd:complexType>
                  
                  <xsd:simpleType name="Amount_Type">
                    <xsd:annotation>
                      <xsd:documentation>Amount</xsd:documentation>
                    </xsd:annotation>
                    <xsd:restriction base="xsd:string">
                      <xsd:maxLength value="12" />
                    </xsd:restriction>
                  </xsd:simpleType>
                  
                  <xsd:simpleType name="Name_Type">
                    <xsd:annotation>
                      <xsd:documentation>Name</xsd:documentation>
                    </xsd:annotation>
                    <xsd:restriction base="xsd:string">
                      <xsd:maxLength value="50" />
                    </xsd:restriction>
                  </xsd:simpleType>
                  

                  推薦答案

                  過去我看到過類似的問題(完全披露,我問過類似的問題 問題我自己).解析 XSD 不適合膽小的人.

                  I have seen similar questions asked in the past (full disclosure, I've ask a similar question myself). Parsing an XSD is not for the faint of heart.

                  您基本上有 2 個選項,第一個更容易實現,但更容易通過對 XSD 的微小更改來破壞.第二個更強大但難以實施.

                  You basically have 2 options, first is easier to implement, but can be broken more easily by minor changes to the XSD. the 2nd is a more robust but hard to implement.

                  選項 1:

                  使用 LINQ(或其他 C# XML 解析器,如果您愿意)解析 XSD.由于 XSD 只是一個 XML,因此您可以將其加載到 XDocument 中,然后通過 LINQ 讀取它.

                  Parsing the XSD with LINQ (or other C# XML parser if you prefer). Since an XSD is just an XML, you can load it into an XDocument and just read it via LINQ.

                  只是您自己的 XSD 示例:

                  For just a sample of your own XSD:

                  <xsd:simpleType name="Amount_Type">
                    <xsd:annotation>
                      <xsd:documentation>Amount</xsd:documentation>
                    </xsd:annotation>
                    <xsd:restriction base="xsd:string">
                      <xsd:maxLength value="12" />
                    </xsd:restriction>
                  </xsd:simpleType>
                  

                  您可以訪問 MaxLength:

                  You can access the MaxLength:

                  var xDoc = XDocument.Load("your XSD path");
                  var ns = XNamespace.Get(@"http://www.w3.org/2001/XMLSchema");
                  
                  var length = (from sType in xDoc.Element(ns + "schema").Elements(ns + "simpleType")
                                where sType.Attribute("name").Value == "Amount_Type"
                                from r in sType.Elements(ns + "restriction")
                                select r.Element(ns + "maxLength").Attribute("value")
                                        .Value).FirstOrDefault();
                  

                  這并沒有提供一種非常簡單的按類型名稱解析的方法,尤其是對于擴展類型.要使用它,您需要知道要查找的每個元素的確切路徑.

                  This does not offer a very easy method for parsing by type name, especially for extended types. To use this you need to know the exact path for each element you are looking for.

                  選項 2:

                  這對于快速回答來說太復雜了(注意:請參閱下面的編輯 - 我有一些時間并制定了一個可行的解決方案),所以我鼓勵你看看我的我在上面鏈接的自己的問題.在其中,我鏈接了一個 很棒的博客,它展示了如何認真地將 XSD 分解為多個部分,并可能允許您執行所需的搜索類型.您必須決定是否值得努力開發它(該博客顯示了一個帶有 XmlReader 的實現,其中包含針對相關 XSD 進行驗證的 XML,但您可以通過直接加載輕松完成此操作XSD 并對其進行解析.

                  This is far too complex for a quick answer (note: see the edit below - I had some time and put together a working solution), so I am going to encourage you to look at my own question I linked above. In it, I linked a great blog that shows how to seriously break down the XSD into pieces and might allow you to perform the type of search you want. You have to decide if it is worth the effort to develop it (the blog shows an implementation with XmlReader that contains an XML that is validated against the XSD in question, but you can easily accomplish this by directly loading the XSD and parsing it.

                  在博客中找到的兩個關鍵思想是:

                  2 key idea to find in the blog are:

                  // in the getRestriction method (reader in this context is an `XmlReader` that 
                  //  contains a XML that is being validated against the specific XSD
                  if (reader.SchemaInfo.SchemaElement == null) return null;
                  simpleType = reader.SchemaInfo.SchemaElement.ElementSchemaType as XmlSchemaSimpleType;
                  if (simpleType == null) return null;
                  restriction = simpleType.Content as XmlSchemaSimpleTypeRestriction;
                  
                  // then in the getMaxLength method
                  if (restriction == null) return null;
                  List<int> result = new List<int>();
                  foreach (XmlSchemaObject facet in restriction.Facets) {
                  if (facet is XmlSchemaMaxLengthFacet) result.Add(int.Parse(((XmlSchemaFacet) facet).Value));
                  

                  去年我實際上嘗試了同樣的事情來解析 XSD 作為復雜數據驗證方法的一部分.我花了一周的大部分時間才真正了解正在發生的事情,并調整博客中的方法以適應我的目的.這絕對是實現您想要的最佳方式.

                  I actually tried the same thing last year to parse an XSD as part of a complicated data validation method. It took me the better part of a week to really understand what was happening an to adapt the methods in the blog to suit my purposes. It is definitely the best way to implement exactly what you want.

                  如果您想使用獨立架構嘗試此操作,可以將 XSD 加載到 XmlSchemaSet 對象中,然后使用 GlobalTypes 屬性幫助您找到特定類型你正在尋找.

                  If you want to try this with a standalone schema, you can load the XSD into an XmlSchemaSet object, then use the GlobalTypes property to help you find the specific type you are looking for.

                  我調出舊代碼并開始整理代碼以幫助您.

                  I pulled up my old code and started putting together the code to help you.

                  首先加載您的架構:

                  XmlSchemaSet set; // this needs to be accessible to the methods below,
                                    //  so should be a class level field or property
                  
                  using (var fs = new FileStream(@"your path here", FileMode.Open)
                  {
                      var schema = XmlSchema.Read(fs, null);
                  
                      set = new XmlSchemaSet();
                      set.Add(schema);
                      set.Compile();
                  }
                  

                  根據您提供的 XSD,以下方法應該可以為您提供接近您想要的結果.它應該非常適合處理更復雜的結構.

                  The following methods should give you close to what you want based on the XSD you provided. It should be pretty adaptable to deal with more complex structures.

                  public Dictionary<string, int> GetElementMaxLength(String xsdElementName)
                  {
                      if (xsdElementName == null) throw new ArgumentException();
                      // if your XSD has a target namespace, you need to replace null with the namespace name
                      var qname = new XmlQualifiedName(xsdElementName, null);
                  
                      // find the type you want in the XmlSchemaSet    
                      var parentType = set.GlobalTypes[qname];
                  
                      // call GetAllMaxLength with the parentType as parameter
                      var results = GetAllMaxLength(parentType);
                  
                      return results;
                  }
                  
                  private Dictionary<string, int> GetAllMaxLength(XmlSchemaObject obj)
                  {
                      Dictionary<string, int> dict = new Dictionary<string, int>();
                  
                      // do some type checking on the XmlSchemaObject
                      if (obj is XmlSchemaSimpleType)
                      {
                          // if it is a simple type, then call GetMaxLength to get the MaxLength restriction
                          var st = obj as XmlSchemaSimpleType;
                          dict[st.QualifiedName.Name] = GetMaxLength(st);
                      }
                      else if (obj is XmlSchemaComplexType)
                      {
                  
                          // if obj is a complexType, cast the particle type to a sequence
                          //  and iterate the sequence
                          //  warning - this will fail if it is not a sequence, so you might need
                          //  to make some adjustments if you have something other than a xs:sequence
                          var ct = obj as XmlSchemaComplexType;
                          var seq = ct.ContentTypeParticle as XmlSchemaSequence;
                  
                          foreach (var item in seq.Items)
                          {
                              // item will be an XmlSchemaObject, so just call this same method
                              //  with item as the parameter to parse it out
                              var rng = GetAllMaxLength(item);
                  
                              // add the results to the dictionary
                              foreach (var kvp in rng)
                              {
                                  dict[kvp.Key] = kvp.Value;
                              }
                          }
                      }
                      else if (obj is XmlSchemaElement)
                      {
                          // if obj is an XmlSchemaElement, the you need to find the type
                          //  based on the SchemaTypeName property.  This is why your 
                          //  XmlSchemaSet needs to have class-level scope
                          var ele = obj as XmlSchemaElement;
                          var type = set.GlobalTypes[ele.SchemaTypeName];
                  
                          // once you have the type, call this method again and get the dictionary result
                          var rng = GetAllMaxLength(type);
                  
                          // put the results in this dictionary.  The difference here is the dictionary
                          //  key is put in the format you specified
                          foreach (var kvp in rng)
                          {
                              dict[String.Format("{0}/{1}", ele.QualifiedName.Name, kvp.Key)] = kvp.Value;
                          }
                      }
                  
                      return dict;
                  }
                  
                  private Int32 GetMaxLength(XmlSchemaSimpleType xsdSimpleType)
                  {
                      // get the content of the simple type
                      var restriction = xsdSimpleType.Content as XmlSchemaSimpleTypeRestriction;
                  
                      // if it is null, then there are no restrictions and return -1 as a marker value
                      if (restriction == null) return -1;
                  
                      Int32 result = -1;
                  
                      // iterate the facets in the restrictions, look for a MaxLengthFacet and parse the value
                      foreach (XmlSchemaObject facet in restriction.Facets)
                      {
                          if (facet is XmlSchemaMaxLengthFacet)
                          {
                              result = int.Parse(((XmlSchemaFacet)facet).Value);
                              break;
                          }
                      }
                  
                      return result;
                  }
                  

                  那么用法就很簡單了,你只需要調用 GetElementMaxLength(String) 方法,它就會以你提供的格式返回一個名稱的字典,并將值作為最大長度:

                  Then the usage is pretty simple, you just need to call the GetElementMaxLength(String) method and it will return a dictionary of the names in the format you provided with the value as the max length:

                  var results = GetElementMaxLength("Setup_Type");
                  
                  foreach (var item in results)
                  {
                      Console.WriteLine("{0} | {1}", item.Key, item.Value);                
                  }
                  

                  這篇關于如何解析 XSD 以從 &lt;xsd:simpleType&gt; 獲取信息使用 C# 的元素?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)

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

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

                  2. <tfoot id='WiFZO'></tfoot>

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

                            <tbody id='WiFZO'></tbody>
                            <bdo id='WiFZO'></bdo><ul id='WiFZO'></ul>
                          • 主站蜘蛛池模板: 欧美精品久久久久久久久久 | 黄色大片网站 | 国产精品福利网 | 91精品久久久久久久久久 | 亚洲高清av在线 | 国产欧美久久一区二区三区 | 精品美女 | 天堂网中文字幕在线观看 | 熟女毛片 | 黄色在线免费观看 | 久在线| 国产清纯白嫩初高生视频在线观看 | 日韩亚洲一区二区 | 中文av电影 | 欧美一级黄色免费 | 国产成人网 | 日韩精品久久久久久 | 国产精品久久久久久亚洲调教 | 第四色影音先锋 | 国产激情91久久精品导航 | 午夜在线小视频 | 国产无人区一区二区三区 | 日本欧美视频 | 亚洲电影一区二区三区 | a级黄色片视频 | 国产精品国产三级国产aⅴ原创 | 欧美精品在线免费观看 | av香港经典三级级 在线 | 成人午夜网站 | 午夜精品在线 | 亚洲永久在线 | 亚洲一av | 激情婷婷| 欧美 日韩 国产 在线 | 亚洲一区 中文字幕 | 国产高清视频一区 | av影音资源| 欧美成人精品一区二区三区 | 一区二区视频在线 | 日韩福利在线 | 亚洲国产精品久久久久婷婷老年 |