Esempio n. 1
0
 private XmlSchemaChoice GetSubstitutionChoice(XmlSchemaElement element)
 {
     if (_substitutionGroupsTable == null)
     {
         BuildSubstitutionGroups();
     }
     if (_substitutionGroupsTable != null)
     {
         SubstitutionGroupWrapper substitutionGroup = (SubstitutionGroupWrapper)_substitutionGroupsTable[element.QualifiedName];
         if (substitutionGroup != null)
         {                 //Element is head of a substitutionGroup
             XmlSchemaChoice choice = new XmlSchemaChoice();
             foreach (XmlSchemaElement elem in substitutionGroup.Members)
             {
                 choice.Items.Add(elem);
             }
             XmlSchemaElement headElement = (XmlSchemaElement)_schemaSet.GlobalElements[element.QualifiedName];
             if (headElement.IsAbstract)
             {                     //Should not generate the abstract element
                 choice.Items.Remove(headElement);
             }
             choice.MinOccurs = element.MinOccurs;
             choice.MaxOccurs = element.MaxOccurs;
             return(choice);
         }
     }
     return(null);
 }
Esempio n. 2
0
 private void BuildSubstitutionGroups()
 {
     foreach (XmlSchemaElement element in _schemaSet.GlobalElements.Values)
     {
         XmlQualifiedName head = element.SubstitutionGroup;
         if (!head.IsEmpty)
         {
             if (_substitutionGroupsTable == null)
             {
                 _substitutionGroupsTable = new Hashtable();
             }
             SubstitutionGroupWrapper substitutionGroup = (SubstitutionGroupWrapper)_substitutionGroupsTable[head];
             if (substitutionGroup == null)
             {
                 substitutionGroup      = new SubstitutionGroupWrapper();
                 substitutionGroup.Head = head;
                 _substitutionGroupsTable.Add(head, substitutionGroup);
             }
             ArrayList members = substitutionGroup.Members;
             if (!members.Contains(element))
             {                     //Members might contain element if the same schema is included and imported through different paths. Imp, hence will be added to set directly
                 members.Add(element);
             }
         }
     }
     if (_substitutionGroupsTable != null)
     {             //There were subst grps in the schema
         foreach (SubstitutionGroupWrapper substGroup in _substitutionGroupsTable.Values)
         {
             ResolveSubstitutionGroup(substGroup);
         }
     }
 }
Esempio n. 3
0
        private void ResolveSubstitutionGroup(SubstitutionGroupWrapper substitutionGroup)
        {
            ArrayList        newMembers  = null;
            XmlSchemaElement headElement = (XmlSchemaElement)_schemaSet.GlobalElements[substitutionGroup.Head];

            if (substitutionGroup.Members.Contains(headElement))
            {            // already checked
                return;
            }
            foreach (XmlSchemaElement element in substitutionGroup.Members)
            {
                //Chain to other head's that are members of this head's substGroup
                SubstitutionGroupWrapper g = (SubstitutionGroupWrapper)_substitutionGroupsTable[element.QualifiedName];
                if (g != null)
                {
                    ResolveSubstitutionGroup(g);
                    foreach (XmlSchemaElement element1 in g.Members)
                    {
                        if (element1 != element)
                        {                         //Exclude the head
                            if (newMembers == null)
                            {
                                newMembers = new ArrayList();
                            }
                            newMembers.Add(element1);
                        }
                    }
                }
            }
            if (newMembers != null)
            {
                foreach (XmlSchemaElement newMember in newMembers)
                {
                    substitutionGroup.Members.Add(newMember);
                }
            }
            substitutionGroup.Members.Add(headElement);
        }