/// <remarks> /// 1. MaxOccurs must be one. (default is also one) /// 2. MinOccurs must be zero or one. /// </remarks> internal override int Compile(ValidationEventHandler h, XmlSchema schema) { // If this is already compiled this time, simply skip. if (CompilationId == schema.CompilationId) { return(0); } this.schema = schema; if (MaxOccurs != Decimal.One) { error(h, "maxOccurs must be 1"); } if (MinOccurs != Decimal.One && MinOccurs != Decimal.Zero) { error(h, "minOccurs must be 0 or 1"); } XmlSchemaUtil.CompileID(Id, this, schema.IDCollection, h); CompileOccurence(h, schema); foreach (XmlSchemaObject obj in Items) { XmlSchemaElement elem = obj as XmlSchemaElement; if (elem != null) { if (elem.ValidatedMaxOccurs != Decimal.One && elem.ValidatedMaxOccurs != Decimal.Zero) { elem.error(h, "The {max occurs} of all the elements of 'all' must be 0 or 1. "); } errorCount += elem.Compile(h, schema); } else { error(h, "XmlSchemaAll can only contain Items of type Element"); } } this.CompilationId = schema.CompilationId; return(errorCount); }
void DoCompile(ValidationEventHandler handler, List <CompiledSchemaMemo> handledUris, XmlSchemaSet col, XmlResolver resolver) { SetParent(); CompilationId = col.CompilationId; schemas = col; if (!schemas.Contains(this)) // e.g. xs:import { schemas.Add(this); } attributeGroups.Clear(); attributes.Clear(); elements.Clear(); groups.Clear(); notations.Clear(); schemaTypes.Clear(); named_identities.Clear(); ids.Clear(); compilationItems.Clear(); //1. Union and List are not allowed in block default if (BlockDefault != XmlSchemaDerivationMethod.All) { if ((BlockDefault & XmlSchemaDerivationMethod.List) != 0) { error(handler, "list is not allowed in blockDefault attribute"); } if ((BlockDefault & XmlSchemaDerivationMethod.Union) != 0) { error(handler, "union is not allowed in blockDefault attribute"); } } //2. Substitution is not allowed in finaldefault. if (FinalDefault != XmlSchemaDerivationMethod.All) { if ((FinalDefault & XmlSchemaDerivationMethod.Substitution) != 0) { error(handler, "substitution is not allowed in finalDefault attribute"); } } //3. id must be of type ID XmlSchemaUtil.CompileID(Id, this, IDCollection, handler); //4. targetNamespace should be of type anyURI or absent if (TargetNamespace != null) { if (TargetNamespace.Length == 0) { error(handler, "The targetNamespace attribute cannot have have empty string as its value."); } if (!XmlSchemaUtil.CheckAnyUri(TargetNamespace)) { error(handler, TargetNamespace + " is not a valid value for targetNamespace attribute of schema"); } } //5. version should be of type normalizedString if (!XmlSchemaUtil.CheckNormalizedString(Version)) { error(handler, Version + "is not a valid value for version attribute of schema"); } // Compile the content of this schema for (int i = 0; i < Items.Count; i++) { compilationItems.Add(Items [i]); } // First, we run into inclusion schemas to collect // compilation target items into compiledItems. for (int i = 0; i < Includes.Count; i++) { ProcessExternal(handler, handledUris, resolver, Includes [i] as XmlSchemaExternal, col); } // Compilation phase. // At least each Compile() must give unique (qualified) name for each component. // It also checks self-resolvable properties correctness. // Post compilation schema information contribution is not done here. // It should be done by Validate(). for (int i = 0; i < compilationItems.Count; i++) { XmlSchemaObject obj = compilationItems [i]; if (obj is XmlSchemaAnnotation) { int numerr = ((XmlSchemaAnnotation)obj).Compile(handler, this); errorCount += numerr; } else if (obj is XmlSchemaAttribute) { XmlSchemaAttribute attr = (XmlSchemaAttribute)obj; int numerr = attr.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable(Attributes, attr, attr.QualifiedName, handler); } } else if (obj is XmlSchemaAttributeGroup) { XmlSchemaAttributeGroup attrgrp = (XmlSchemaAttributeGroup)obj; int numerr = attrgrp.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( AttributeGroups, attrgrp, attrgrp.QualifiedName, handler); } } else if (obj is XmlSchemaComplexType) { XmlSchemaComplexType ctype = (XmlSchemaComplexType)obj; int numerr = ctype.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( schemaTypes, ctype, ctype.QualifiedName, handler); } } else if (obj is XmlSchemaSimpleType) { XmlSchemaSimpleType stype = (XmlSchemaSimpleType)obj; stype.islocal = false; //This simple type is toplevel int numerr = stype.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( SchemaTypes, stype, stype.QualifiedName, handler); } } else if (obj is XmlSchemaElement) { XmlSchemaElement elem = (XmlSchemaElement)obj; elem.parentIsSchema = true; int numerr = elem.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( Elements, elem, elem.QualifiedName, handler); } } else if (obj is XmlSchemaGroup) { XmlSchemaGroup grp = (XmlSchemaGroup)obj; int numerr = grp.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( Groups, grp, grp.QualifiedName, handler); } } else if (obj is XmlSchemaNotation) { XmlSchemaNotation ntn = (XmlSchemaNotation)obj; int numerr = ntn.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( Notations, ntn, ntn.QualifiedName, handler); } } else { ValidationHandler.RaiseValidationEvent( handler, null, String.Format("Object of Type {0} is not valid in Item Property of Schema", obj.GetType().Name), null, this, null, XmlSeverityType.Error); } } }