Example #1
0
        void GetAnnotations()
        {
            XmlSchemaSummary xss = new XmlSchemaSummary(this.element);

            if (!string.IsNullOrEmpty(xss.Text))
            {
                this.summary = xss.Text;
                return;
            }
            xss          = new XmlSchemaSummary(this.ComplexType);
            this.summary = xss.Text;
        }
Example #2
0
        void AnalyzeElement(XmlSchemaElement element, XmlSchemaElement parentElement)
        {
            ElementWrapper elementWrapper = new ElementWrapper(element);

            this.validationMessages.AddRange(elementWrapper.Warnings);
            // Don't process simple types
            if (!elementWrapper.IsComplexType)
            {
                return;
            }
            string elementTypeName = elementWrapper.TypeName;

            bool skip = elementWrapper.IsComplexType && elementWrapper.SimpleSubElements.Count == 0 && elementWrapper.Attributes.Count == 0 && elementWrapper.ComplexSubElements.Count < 2;
            bool isAlreadyGenerated = false;

            if (!skip)
            {
                DataTable dt;
                if (generatedDataSet.Tables.Contains(elementTypeName))
                {
                    dt = generatedDataSet.Tables[elementTypeName];
                    isAlreadyGenerated = true;
                }
                else
                {
                    dt = new DataTable(elementTypeName);
                    if (!string.IsNullOrEmpty(elementWrapper.Summary))
                    {
                        dt.ExtendedProperties.Add("summary", elementWrapper.Summary);
                    }
                    generatedDataSet.Tables.Add(dt);
                }
                if (!isAlreadyGenerated)
                {
                    foreach (XmlSchemaAttribute attrObj in elementWrapper.Attributes)
                    {
                        Type             t   = GetClrType(attrObj.SchemaTypeName);
                        DataColumn       dc  = dt.Columns.Add(attrObj.Name, t);
                        XmlSchemaSummary sum = new XmlSchemaSummary(attrObj);
                        if (!string.IsNullOrEmpty(sum.Text))
                        {
                            dc.ExtendedProperties.Add("summary", sum.Text);
                        }
                        //						dc.ExtendedProperties.Add( "schemaType", "Attribute" );
                    }
                    foreach (XmlSchemaElement subElement in elementWrapper.SimpleSubElements)
                    {
                        Type t = GetClrType(subElement);
                        if (/* subElement == element && */ t == null) //TODO: Check all cases with subElement != element
                        {
                            continue;                                 // element seemed to have an own type, but it's xs:any or something undetermined
                        }
                        string columnName = null;
                        if (subElement == element)
                        {
                            columnName = "Value";
                        }
                        else
                        {
                            columnName = subElement.Name;
                        }
                        DataColumn dc = dt.Columns.Add(columnName, t);
                        dc.ExtendedProperties.Add("schemaType", "Element");
                    }
                }
            }
            if (isAlreadyGenerated)
            {
                return;
            }
            //----------------------

            foreach (XmlSchemaElement subEl in elementWrapper.ComplexSubElements)
            {
                ElementWrapper subElementWrapper = new ElementWrapper(subEl, false);
                // Now add the relation
                if (!(skip && parentElement == null)) // otherwise we omit the root element
                {
                    RelationEntry relEntry = new RelationEntry();
                    string        ownName  = this.namespaceWrapper.GetXPath(subElementWrapper.QualifiedName);
                    if (!skip)
                    {
                        relEntry.ParentTable = elementTypeName;
                        relEntry.XPath       = ownName;
                    }
                    else
                    {
                        ElementWrapper parentElementWrapper = new ElementWrapper(parentElement, false);
                        relEntry.ParentTable = parentElementWrapper.TypeName;
                        string parentName = this.namespaceWrapper.GetXPath(elementWrapper.QualifiedName);
                        relEntry.XPath = parentName + "/" + ownName;
                    }
                    relEntry.ChildTable = subElementWrapper.TypeName;

                    this.relations.Add(relEntry);
                }

                if (subElementWrapper.TypeName == elementTypeName)
                {
                    continue;  // don't walk into endless recursion
                }
                AnalyzeElement(subEl, skip ? parentElement : element);
            }
        }