How programmatically extract enumeration constraint values of an element from xsd schema file using .net?
for example I'd like to extract 'Audi', 'Golf' and 'BMW' from the following xsd:
<xs:element name="car">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Audi"/>
<xs:enumeration value="Golf"/>
<xs:enumeration value="BMW"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
There is an XmlSchema
class, but it looks pretty... "fun" to work with.
Would xml querying be enough?
XmlDocument doc = new XmlDocument();
doc.Load("Foo.xsd");
XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable);
mgr.AddNamespace("xx", "http://www.w3.org/2001/XMLSchema");
foreach (XmlElement el in doc.SelectNodes("//xx:element[@name='car'][1]/xx:simpleType/xx:restriction/xx:enumeration", mgr))
{
Console.WriteLine(el.GetAttribute("value"));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With