Exemplo n.º 1
0
        /// <summary>
        /// Creates a group that contains all of the elements that may be children of the root.
        /// That is, all types, and and explicit relationship instances.
        /// </summary>
        private void AddRootChildren()
        {
            // Example of inheritance declaration
            //<xs:group name="rootchildren">
            //  <xs:choice>
            //    <xs:element ref="person" />
            //    <xs:element ref="employee" />
            //    <xs:element ref="manager" />
            //    <xs:element ref="worksFor.instance" />
            //  </xs:choice>
            //</xs:group>


            // Create a group, named "rootchildren"
            var rootChildrenGroup = new XmlSchemaGroup();

            rootChildrenGroup.Name     = "rootchildren";
            rootChildrenGroup.Particle = new XmlSchemaChoice();

            // All types
            var types = EffectiveTypes(_schemaManager.GetInstancesOfType(A(Aliases.Type)));

            foreach (EffectiveType type in types)
            {
                bool isAbstract = _schemaManager.GetBoolFieldValue(type.Type, Aliases2.IsAbstract);
                if (isAbstract)
                {
                    continue;
                }

                var typeElement = new XmlSchemaElement();
                typeElement.RefName = NameUsed(type.Alias.ToQualifiedName());
                rootChildrenGroup.Particle.Items.Add(typeElement);
            }

            // All relationships
            var relationships = EffectiveRelationships(_schemaManager.GetInstancesOfType(A(Aliases.Relationship)));

            foreach (EffectiveRelationship relationship in relationships)
            {
                var relElement = new XmlSchemaElement();
                relElement.RefName = NameUsed(relationship.Alias.ToQualifiedName(suffix: XmlParser.RelationshipInstanceSuffix));
                rootChildrenGroup.Particle.Items.Add(relElement);
            }

            XmlSchema xsd = GetSchema(Aliases.CoreNamespace);

            xsd.Items.Insert(0, rootChildrenGroup);
        }