private XmlSchemaElement FindDatasetElement(XmlSchemaObjectCollection elements)
{
foreach (XmlSchemaElement XmlElement in elements)
{
if (GetBooleanAttribute(XmlElement, Keywords.MSD_ISDATASET, /*default:*/ false))
return XmlElement;
}
if ((elements.Count == 1) || (FromInference && elements.Count > 0))
{ //let's see if this element looks like a DataSet
XmlSchemaElement node = (XmlSchemaElement)elements[0];
if (!GetBooleanAttribute(node, Keywords.MSD_ISDATASET, /*default:*/ true))
return null;
XmlSchemaComplexType ct = node.SchemaType as XmlSchemaComplexType;
if (ct == null)
return null;
while (ct != null)
{
if (HasAttributes(ct.Attributes))
return null;
if (ct.ContentModel is XmlSchemaSimpleContent)
{
XmlSchemaAnnotated cContent = ((XmlSchemaSimpleContent)(ct.ContentModel)).Content;
if (cContent is XmlSchemaSimpleContentExtension)
{
XmlSchemaSimpleContentExtension ccExtension = ((XmlSchemaSimpleContentExtension)cContent);
if (HasAttributes(ccExtension.Attributes))
return null;
}
else
{
XmlSchemaSimpleContentRestriction ccRestriction = ((XmlSchemaSimpleContentRestriction)cContent);
if (HasAttributes(ccRestriction.Attributes))
return null;
}
}
XmlSchemaParticle particle = GetParticle(ct);
if (particle != null)
{
if (!IsDatasetParticle(particle))
return null; // it's a table
}
if (ct.BaseXmlSchemaType is XmlSchemaComplexType)
ct = (XmlSchemaComplexType)ct.BaseXmlSchemaType;
else
break;
}
//if we are here there all elements are tables
return node;
}
return null;
}