I am trying to extract enumeration values from an xsd file but am failing and the only code to assist is below, which only gets me the numeric value.
XSD File:
<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>...
The code I have tried using:
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));
I am trying to extract the name and description of the xsd documentation, e.g. "Bag, super bulk" etc