我正在尝试从 xsd 文件中提取枚举值,但失败了,下面是唯一可以帮助的代码,它只能让我得到数值。
XSD 文件:
<xsd:simpleType name="PackageTypeCodeContentType">
<xsd:restriction base="xsd:token">
<xsd:enumeration value="43">
<xsd:annotation>
<xsd:documentation xml:lang="en">
<ccts:Name>Bag, super bulk</ccts:Name>
</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="44">
<xsd:annotation>
<xsd:documentation xml:lang="en">
<ccts:Name>Bag, polybag</ccts:Name>
<ccts:Description>A type of plastic bag, typically used to wrap promotional pieces, publications, product samples, and/or catalogues.</ccts:Description>
</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="1A">
<xsd:annotation>
<xsd:documentation xml:lang="en">
<ccts:Name>Drum, steel</ccts:Name>
</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>...
我尝试使用的代码:
XmlSchema schema = XmlSchema.Read(XmlReader.Create("XsdLookups\\PackageType.xsd"), ValidationCallbackOne);
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.Add(schema);
schemaSet.Compile();
var results = schema.Items.OfType<XmlSchemaSimpleType>().Where(s => (s.Content is XmlSchemaSimpleTypeRestriction) && s.Name == "PackageTypeCodeContentType").ToList();
var enumValues = results.SelectMany(c => ((XmlSchemaSimpleTypeRestriction)c.Content).Facets.OfType<XmlSchemaEnumerationFacet>().Select(d => d.Value));
enumValues.ToList().ForEach(p=> Debug.WriteLine(p));
我正在尝试提取 xsd 文档的名称和描述,例如“Bag,super bulk”等