Csharp/C#教程:如何使用c#在简单的xsd元素中查找限制值分享


如何使用c#在简单的xsd元素中查找限制值

如何使用c#在xsd simpleType上检索这些枚举类型? 这是一个简单类型的示例?

      

谢谢

您可以在此代码中查看使用模式对象模型(SOM):

 using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Xml; using System.Xml.Schema; namespace Testing.Xml { class Program { static void Main(string[] args) { // read the schema XmlSchema schema; using (var reader = new StreamReader(@"c:pathtoschema.xsd")) { schema = XmlSchema.Read(reader, null); } // compile so that post-compilation information is available XmlSchemaSet schemaSet = new XmlSchemaSet(); schemaSet.Add(schema); schemaSet.Compile(); // update schema reference schema = schemaSet.Schemas().Cast().First(); var simpleTypes = schema.SchemaTypes.Values.OfType() .Where(t => t.Content is XmlSchemaSimpleTypeRestriction); foreach (var simpleType in simpleTypes) { var restriction = (XmlSchemaSimpleTypeRestriction) simpleType.Content; var enumFacets = restriction.Facets.OfType(); if (enumFacets.Any()) { Console.WriteLine("" + simpleType.Name); foreach (var facet in enumFacets) { Console.WriteLine(facet.Value); } } } } } } 

此代码仅适用于命名的简单类型 – 如果您有包含匿名简单类型的元素或属性,那么它会变得更复杂,因为您必须遍历所有元素和属性以查找具有枚举方面的限制内容的简单类型。

上述就是C#学习教程:如何使用c#在简单的xsd元素中查找限制值分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/955061.html

(0)
上一篇 2021年11月21日
下一篇 2021年11月21日

精彩推荐