public static List<XmlSchemaElement> extractElements(XmlSchema schema)
{
List<XmlSchemaElement> elements = new List<XmlSchemaElement>();
foreach (object item in schema.Elements)
{
if (item is DictionaryEntry)
{
DictionaryEntry entry = (DictionaryEntry)item;
XmlSchemaElement element = entry.Value as XmlSchemaElement;
if (element != null)
{
elements.Add(element);
}
}
}
foreach (object item in schema.Items)
{
if (item is XmlSchemaElement)
{
XmlSchemaElement element = item as XmlSchemaElement;
if( !elements.Exists(el => el == element ))
elements.Add(element);
}
}
return elements;
}