Пример #1
0
 private void CompileContentModel(CompiledContentModel compiledContentModel, XmlSchemaParticle particle) {
     if (particle is XmlSchemaElement) {
         compiledContentModel.AddTerminal(((XmlSchemaElement)particle).QualifiedName, null, this.validationEventHandler);       
     }
     else if (particle is XmlSchemaAny) {
         compiledContentModel.AddAny((XmlSchemaAny)particle);
     }
     else if (particle is XmlSchemaGroupRef) {
         XmlSchemaParticle realParticle = ((XmlSchemaGroupRef)particle).Particle;
         Debug.Assert(realParticle != null && !realParticle.IsEmpty);
         compiledContentModel.OpenGroup();
         CompileContentModel(compiledContentModel, realParticle);              
         compiledContentModel.CloseGroup();
     }
     else if (particle is XmlSchemaAll) {
         XmlSchemaAll all = (XmlSchemaAll)particle;
         compiledContentModel.StartAllElements(all.Items.Count);
         foreach (XmlSchemaElement localElement in all.Items) {
             if (!compiledContentModel.AddAllElement(localElement.QualifiedName, (all.MinOccurs == decimal.One ? localElement.MinOccurs == decimal.One : false))) {
                SendValidationEvent(Res.Sch_DupElement, localElement.QualifiedName.ToString(), localElement);
             }
         }              
     }
     else if (particle is XmlSchemaGroupBase) {
         XmlSchemaObjectCollection particles = ((XmlSchemaGroupBase)particle).Items;
         bool isChoice = particle is XmlSchemaChoice;
         compiledContentModel.OpenGroup();
         bool first = true;
         foreach (XmlSchemaParticle p in particles) {
             if (first) {
                 first = false;
             }
             else if (isChoice) {
                 compiledContentModel.AddChoice();  
             }
             else {
                 compiledContentModel.AddSequence();
             }
             Debug.Assert(!p.IsEmpty);
             CompileContentModel(compiledContentModel, p);
         }
         compiledContentModel.CloseGroup();
     }
     else {
         Debug.Assert(false);
     }
     if (particle.MinOccurs == decimal.One && particle.MaxOccurs == decimal.One) {
         // nothing
     }
     else if (particle.MinOccurs == decimal.Zero && particle.MaxOccurs == decimal.One) {
         compiledContentModel.QuestionMark();
     }
     else if (particle.MinOccurs == decimal.Zero && particle.MaxOccurs == decimal.MaxValue) {
         compiledContentModel.Star();
     }
     else if (particle.MinOccurs == decimal.One && particle.MaxOccurs == decimal.MaxValue) {
         compiledContentModel.Plus();
     }
     else {
         compiledContentModel.MinMax(particle.MinOccurs, particle.MaxOccurs);
     }
 }
Пример #2
0
 private static void HandleMinMax(CompiledContentModel pContent, uint cMin, uint cMax) {
     if (cMax == uint.MaxValue) {
         if (cMin == 0)
             pContent.Star();           // minOccurs="0" and maxOccurs="infinite"
         else
             pContent.Plus();           // minOccurs="1" and maxOccurs="infinite"
     }
     else if (cMin == 0) {                 // minOccurs="0" and maxOccurs="1")
         pContent.QuestionMark();
     }
 }