internal override int Compile(ValidationEventHandler h, XmlSchema schema) { if (this.CompilationId == schema.CompilationId) { return(0); } if (this.Name == null) { base.error(h, "Required attribute name must be present"); } else if (!XmlSchemaUtil.CheckNCName(this.name)) { base.error(h, "attribute name must be NCName"); } else { this.qName = new XmlQualifiedName(this.Name, base.AncestorSchema.TargetNamespace); if (schema.NamedIdentities.Contains(this.qName)) { XmlSchemaIdentityConstraint xmlSchemaIdentityConstraint = schema.NamedIdentities[this.qName] as XmlSchemaIdentityConstraint; base.error(h, string.Format("There is already same named identity constraint in this namespace. Existing item is at {0}({1},{2})", xmlSchemaIdentityConstraint.SourceUri, xmlSchemaIdentityConstraint.LineNumber, xmlSchemaIdentityConstraint.LinePosition)); } else { schema.NamedIdentities.Add(this.qName, this); } } if (this.Selector == null) { base.error(h, "selector must be present"); } else { this.Selector.isSelector = true; this.errorCount += this.Selector.Compile(h, schema); if (this.selector.errorCount == 0) { this.compiledSelector = new XsdIdentitySelector(this.Selector); } } if (this.errorCount > 0) { return(this.errorCount); } if (this.Fields.Count == 0) { base.error(h, "atleast one field value must be present"); } else { for (int i = 0; i < this.Fields.Count; i++) { XmlSchemaXPath xmlSchemaXPath = this.Fields[i] as XmlSchemaXPath; if (xmlSchemaXPath != null) { this.errorCount += xmlSchemaXPath.Compile(h, schema); if (xmlSchemaXPath.errorCount == 0) { this.compiledSelector.AddField(new XsdIdentityField(xmlSchemaXPath, i)); } } else { base.error(h, "Object of type " + this.Fields[i].GetType() + " is invalid in the Fields Collection"); } } } XmlSchemaUtil.CompileID(base.Id, this, schema.IDCollection, h); this.CompilationId = schema.CompilationId; return(this.errorCount); }
/// <remarks> /// 1. name must be present /// 2. selector and field must be present /// </remarks> internal override int Compile(ValidationEventHandler h, XmlSchema schema) { // If this is already compiled this time, simply skip. if (CompilationId == schema.CompilationId) { return(0); } if (Name == null) { error(h, "Required attribute name must be present"); } else if (!XmlSchemaUtil.CheckNCName(this.name)) { error(h, "attribute name must be NCName"); } else { this.qName = new XmlQualifiedName(Name, AncestorSchema.TargetNamespace); if (schema.NamedIdentities.Contains(qName)) { XmlSchemaIdentityConstraint existing = schema.NamedIdentities [qName] as XmlSchemaIdentityConstraint; error(h, String.Format("There is already same named identity constraint in this namespace. Existing item is at {0}({1},{2})", existing.SourceUri, existing.LineNumber, existing.LinePosition)); } else { schema.NamedIdentities.Add(qName, this); } } if (Selector == null) { error(h, "selector must be present"); } else { Selector.isSelector = true; errorCount += Selector.Compile(h, schema); if (selector.errorCount == 0) { compiledSelector = new XsdIdentitySelector(Selector); } } if (errorCount > 0) { return(errorCount); // fatal } if (Fields.Count == 0) { error(h, "atleast one field value must be present"); } else { for (int i = 0; i < Fields.Count; i++) { XmlSchemaXPath field = Fields [i] as XmlSchemaXPath; if (field != null) { errorCount += field.Compile(h, schema); if (field.errorCount == 0) { this.compiledSelector.AddField(new XsdIdentityField(field, i)); } } else { error(h, "Object of type " + Fields [i].GetType() + " is invalid in the Fields Collection"); } } } XmlSchemaUtil.CompileID(Id, this, schema.IDCollection, h); this.CompilationId = schema.CompilationId; return(errorCount); }