Extract enumeration data from .XSD file
Posted
by Ram
on Stack Overflow
See other posts from Stack Overflow
or by Ram
Published on 2010-05-24T10:16:13Z
Indexed on
2010/05/24
10:21 UTC
Read the original article
Hit count: 377
Hi,
I am trying to read enum from a XSD file. The schema is as follows
<xs:schema id="ShipReports-v1.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="unqualified" elementFormDefault="qualified" msdata:IsDataSet="true">
<xs:simpleType name="Type">
<xs:restriction base="xs:string">
<xs:enumeration value="Op1" />
<xs:enumeration value="Op2" />
<xs:enumeration value="Op3" />
</xs:restriction>
</xs:simpleType>
</xs:schema>
I also tried using this but I am getting list item count as Zero. Following is the code I am using
DataSet _sR = new DataSet();
_sR.ReadXmlSchema(assembly.GetManifestResourceStream("v1.xsd"));
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(_sR.GetXml());
XmlNamespaceManager xMan = new XmlNamespaceManager(xDoc.NameTable);
xMan.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
XmlNodeList xNodeList = xDoc.SelectNodes(
"//xs:schema/xs:simpleType[@name='Type']/xs:enumeration", xMan);
string[] enumVal = new string[xNodeList.Count];
int ctr = 0;
foreach (XmlNode xNode in xNodeList)
{
enumVal[ctr] = xNode.Attributes["value"].Value;
ctr++;
}
© Stack Overflow or respective owner