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.qualifiedName = new XmlQualifiedName(this.Name, base.AncestorSchema.TargetNamespace); } if (this.Public == null) { base.error(h, "public must be present"); } else if (!XmlSchemaUtil.CheckAnyUri(this.Public)) { base.error(h, "public must be anyURI"); } if (this.system != null && !XmlSchemaUtil.CheckAnyUri(this.system)) { base.error(h, "system must be present and of Type anyURI"); } XmlSchemaUtil.CompileID(base.Id, this, schema.IDCollection, h); return(this.errorCount); }
/// <remarks> /// An Attribute group can only be defined as a child of XmlSchema or in XmlSchemaRedefine. /// The other attributeGroup has type XmlSchemaAttributeGroupRef. /// 1. Name 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(errorCount); } errorCount = 0; if (redefinedObject != null) { errorCount += redefined.Compile(h, schema); if (errorCount == 0) { redefined = (XmlSchemaAttributeGroup)redefinedObject; } } XmlSchemaUtil.CompileID(Id, this, schema.IDCollection, h); if (this.Name == null || this.Name == String.Empty) //1 { error(h, "Name is required in top level simpletype"); } else if (!XmlSchemaUtil.CheckNCName(this.Name)) // b.1.2 { error(h, "name attribute of a simpleType must be NCName"); } else { this.qualifiedName = new XmlQualifiedName(this.Name, AncestorSchema.TargetNamespace); } if (this.AnyAttribute != null) { errorCount += this.AnyAttribute.Compile(h, schema); } foreach (XmlSchemaObject obj in Attributes) { if (obj is XmlSchemaAttribute) { XmlSchemaAttribute attr = (XmlSchemaAttribute)obj; errorCount += attr.Compile(h, schema); } else if (obj is XmlSchemaAttributeGroupRef) { XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef)obj; errorCount += gref.Compile(h, schema); } else { error(h, "invalid type of object in Attributes property"); } } this.CompilationId = schema.CompilationId; return(errorCount); }
private void CompileCommon(ValidationEventHandler h, XmlSchema schema, bool refIsNotPresent) { if (refIsNotPresent) { 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 if (this.Name == "xmlns") { base.error(h, "attribute name must not be xmlns"); } else { this.qualifiedName = new XmlQualifiedName(this.Name, this.targetNamespace); } if (this.SchemaType != null) { if (this.SchemaTypeName != null && !this.SchemaTypeName.IsEmpty) { base.error(h, "attribute can't have both a type and <simpleType> content"); } this.errorCount += this.SchemaType.Compile(h, schema); } if (this.SchemaTypeName != null && !XmlSchemaUtil.CheckQName(this.SchemaTypeName)) { base.error(h, this.SchemaTypeName + " is not a valid QName"); } } else { if (this.RefName == null || this.RefName.IsEmpty) { throw new InvalidOperationException("Error: Should Never Happen. refname must be present"); } this.qualifiedName = this.RefName; } if (base.AncestorSchema.TargetNamespace == "http://www.w3.org/2001/XMLSchema-instance" && this.Name != "nil" && this.Name != "type" && this.Name != "schemaLocation" && this.Name != "noNamespaceSchemaLocation") { base.error(h, "targetNamespace can't be http://www.w3.org/2001/XMLSchema-instance"); } if (this.DefaultValue != null && this.FixedValue != null) { base.error(h, "default and fixed must not both be present in an Attribute"); } if (this.DefaultValue != null && this.Use != XmlSchemaUse.None && this.Use != XmlSchemaUse.Optional) { base.error(h, "if default is present, use must be optional"); } XmlSchemaUtil.CompileID(base.Id, this, schema.IDCollection, h); }
internal override int Compile(ValidationEventHandler h, XmlSchema schema) { if (this.CompilationId == schema.CompilationId) { return(this.errorCount); } this.errorCount = 0; if (this.redefinedObject != null) { this.errorCount += this.redefined.Compile(h, schema); if (this.errorCount == 0) { this.redefined = (XmlSchemaAttributeGroup)this.redefinedObject; } } XmlSchemaUtil.CompileID(base.Id, this, schema.IDCollection, h); if (this.Name == null || this.Name == string.Empty) { base.error(h, "Name is required in top level simpletype"); } else if (!XmlSchemaUtil.CheckNCName(this.Name)) { base.error(h, "name attribute of a simpleType must be NCName"); } else { this.qualifiedName = new XmlQualifiedName(this.Name, base.AncestorSchema.TargetNamespace); } if (this.AnyAttribute != null) { this.errorCount += this.AnyAttribute.Compile(h, schema); } foreach (XmlSchemaObject xmlSchemaObject in this.Attributes) { if (xmlSchemaObject is XmlSchemaAttribute) { XmlSchemaAttribute xmlSchemaAttribute = (XmlSchemaAttribute)xmlSchemaObject; this.errorCount += xmlSchemaAttribute.Compile(h, schema); } else if (xmlSchemaObject is XmlSchemaAttributeGroupRef) { XmlSchemaAttributeGroupRef xmlSchemaAttributeGroupRef = (XmlSchemaAttributeGroupRef)xmlSchemaObject; this.errorCount += xmlSchemaAttributeGroupRef.Compile(h, schema); } else { base.error(h, "invalid type of object in Attributes property"); } } this.CompilationId = schema.CompilationId; return(this.errorCount); }
public static bool IsValidQName(string qname) { foreach (string name in qname.Split(new char[] { ':' }, 2)) { if (!XmlSchemaUtil.CheckNCName(name)) { return(false); } } return(true); }
// 1. name must be present // 2. MinOccurs & MaxOccurs of the Particle must be absent 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 { qualifiedName = new XmlQualifiedName(Name, AncestorSchema.TargetNamespace); } if (Particle == null) { error(h, "Particle is required"); } else { if (Particle.MaxOccursString != null) { Particle.error(h, "MaxOccurs must not be present when the Particle is a child of Group"); } if (Particle.MinOccursString != null) { Particle.error(h, "MinOccurs must not be present when the Particle is a child of Group"); } Particle.Compile(h, schema); } XmlSchemaUtil.CompileID(Id, this, schema.IDCollection, h); this.CompilationId = schema.CompilationId; return(errorCount); }
public static void CompileID(string id, XmlSchemaObject xso, Hashtable idCollection, ValidationEventHandler h) { if (id == null) { return; } if (!XmlSchemaUtil.CheckNCName(id)) { xso.error(h, id + " is not a valid id attribute"); } else if (idCollection.ContainsKey(id)) { xso.error(h, "Duplicate id attribute " + id); } else { idCollection.Add(id, xso); } }
// 1. name and public must be present // public and system must be anyURI 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 { qualifiedName = new XmlQualifiedName(Name, AncestorSchema.TargetNamespace); } if (Public == null) { error(h, "public must be present"); } else if (!XmlSchemaUtil.CheckAnyUri(Public)) { error(h, "public must be anyURI"); } if (system != null && !XmlSchemaUtil.CheckAnyUri(system)) { error(h, "system must be present and of Type anyURI"); } XmlSchemaUtil.CompileID(Id, this, schema.IDCollection, h); return(errorCount); }
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.qualifiedName = new XmlQualifiedName(this.Name, base.AncestorSchema.TargetNamespace); } if (this.Particle == null) { base.error(h, "Particle is required"); } else { if (this.Particle.MaxOccursString != null) { this.Particle.error(h, "MaxOccurs must not be present when the Particle is a child of Group"); } if (this.Particle.MinOccursString != null) { this.Particle.error(h, "MinOccurs must not be present when the Particle is a child of Group"); } this.Particle.Compile(h, schema); } XmlSchemaUtil.CompileID(base.Id, this, schema.IDCollection, h); this.CompilationId = schema.CompilationId; return(this.errorCount); }
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> /// For a simple Type: /// 1. Content must be present /// 2. id if present, must have be a valid ID /// a) If the simpletype is local /// 1- are from <xs:complexType name="simpleType"> and <xs:complexType name="localSimpleType"> /// 1. name is prohibited /// 2. final is prohibited /// b) If the simpletype is toplevel /// 1- are from <xs:complexType name="simpleType"> and <xs:complexType name="topLevelSimpleType"> /// 1. name is required, type must be NCName /// 2. Content is required /// 3. final can have values : #all | (list | union | restriction) /// 4. If final is set, finalResolved is same as final (but within the values of b.3) /// 5. If final is not set, the finalDefault of the schema (ie. only #all and restriction) /// 6. Base type is: /// 4.1 If restriction is chosen,the base type of restriction or elements /// 4.2 otherwise simple ur-type /// </remarks> internal override int Compile(ValidationEventHandler h, XmlSchema schema) { // If this is already compiled this time, simply skip. if (CompilationId == schema.CompilationId) { return(0); } errorCount = 0; if (this.islocal) // a { if (this.Name != null) // a.1 { error(h, "Name is prohibited in a local simpletype"); } else { this.QNameInternal = new XmlQualifiedName(this.Name, AncestorSchema.TargetNamespace); } if (this.Final != XmlSchemaDerivationMethod.None) //a.2 { error(h, "Final is prohibited in a local simpletype"); } } else //b { if (this.Name == null) //b.1 { error(h, "Name is required in top level simpletype"); } else if (!XmlSchemaUtil.CheckNCName(this.Name)) // b.1.2 { error(h, "name attribute of a simpleType must be NCName"); } else { this.QNameInternal = new XmlQualifiedName(this.Name, AncestorSchema.TargetNamespace); } //NOTE: Although the FinalResolved can be Empty, it is not a valid value for Final //DEVIATION: If an error occurs, the finaldefault is always consulted. This deviates // from the way MS implementation works. switch (this.Final) //b.3, b.4 { case XmlSchemaDerivationMethod.All: this.finalResolved = XmlSchemaDerivationMethod.All; break; case XmlSchemaDerivationMethod.List: case XmlSchemaDerivationMethod.Union: case XmlSchemaDerivationMethod.Restriction: this.finalResolved = Final; break; default: error(h, "The value of final attribute is not valid for simpleType"); goto case XmlSchemaDerivationMethod.None; // use assignment from finaldefault on schema. case XmlSchemaDerivationMethod.None: // b.5 XmlSchemaDerivationMethod flags = (XmlSchemaDerivationMethod.Restriction | XmlSchemaDerivationMethod.List | XmlSchemaDerivationMethod.Extension | XmlSchemaDerivationMethod.Union); switch (schema.FinalDefault) { case XmlSchemaDerivationMethod.All: finalResolved = XmlSchemaDerivationMethod.All; break; case XmlSchemaDerivationMethod.None: finalResolved = XmlSchemaDerivationMethod.Empty; break; default: finalResolved = schema.FinalDefault & flags; break; } break; } } XmlSchemaUtil.CompileID(Id, this, schema.IDCollection, h); if (Content != null) { Content.OwnerType = this; } if (this.Content == null) //a.3,b.2 { error(h, "Content is required in a simpletype"); } else if (Content is XmlSchemaSimpleTypeRestriction) { this.resolvedDerivedBy = XmlSchemaDerivationMethod.Restriction; errorCount += ((XmlSchemaSimpleTypeRestriction)Content).Compile(h, schema); } else if (Content is XmlSchemaSimpleTypeList) { this.resolvedDerivedBy = XmlSchemaDerivationMethod.List; errorCount += ((XmlSchemaSimpleTypeList)Content).Compile(h, schema); } else if (Content is XmlSchemaSimpleTypeUnion) { this.resolvedDerivedBy = XmlSchemaDerivationMethod.Union; errorCount += ((XmlSchemaSimpleTypeUnion)Content).Compile(h, schema); } this.CompilationId = schema.CompilationId; return(errorCount); }
private void CompileCommon(ValidationEventHandler h, XmlSchema schema, bool refIsNotPresent) { if (refIsNotPresent) { if (Name == null) //a.4, b.1, { error(h, "Required attribute name must be present"); } else if (!XmlSchemaUtil.CheckNCName(Name)) // a.4.2, b1.2 { error(h, "attribute name must be NCName"); } else if (Name == "xmlns") // a.14 , b5 { error(h, "attribute name must not be xmlns"); } else { qualifiedName = new XmlQualifiedName(Name, targetNamespace); } if (SchemaType != null) { if (SchemaTypeName != null && !SchemaTypeName.IsEmpty) // a.8 { error(h, "attribute can't have both a type and <simpleType> content"); } errorCount += SchemaType.Compile(h, schema); } if (SchemaTypeName != null && !XmlSchemaUtil.CheckQName(SchemaTypeName)) { error(h, SchemaTypeName + " is not a valid QName"); } } else { if (RefName == null || RefName.IsEmpty) { throw new InvalidOperationException("Error: Should Never Happen. refname must be present"); } else { qualifiedName = RefName; } } if (AncestorSchema.TargetNamespace == XmlSchema.InstanceNamespace && Name != "nil" && Name != "type" && Name != "schemaLocation" && Name != "noNamespaceSchemaLocation") // a.15, a.16 { error(h, "targetNamespace can't be " + XmlSchema.InstanceNamespace); } if (DefaultValue != null && FixedValue != null) // a.6, b.3, c.3 { error(h, "default and fixed must not both be present in an Attribute"); } if (DefaultValue != null && Use != XmlSchemaUse.None && Use != XmlSchemaUse.Optional) { error(h, "if default is present, use must be optional"); } XmlSchemaUtil.CompileID(Id, this, schema.IDCollection, h); }
/// <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); }
internal override int Compile(ValidationEventHandler h, XmlSchema schema) { if (this.CompilationId == schema.CompilationId) { return(0); } this.errorCount = 0; if (this.islocal) { if (base.Name != null) { base.error(h, "Name is prohibited in a local simpletype"); } else { this.QNameInternal = new XmlQualifiedName(base.Name, base.AncestorSchema.TargetNamespace); } if (base.Final != XmlSchemaDerivationMethod.None) { base.error(h, "Final is prohibited in a local simpletype"); } } else { if (base.Name == null) { base.error(h, "Name is required in top level simpletype"); } else if (!XmlSchemaUtil.CheckNCName(base.Name)) { base.error(h, "name attribute of a simpleType must be NCName"); } else { this.QNameInternal = new XmlQualifiedName(base.Name, base.AncestorSchema.TargetNamespace); } XmlSchemaDerivationMethod final = base.Final; if (final != XmlSchemaDerivationMethod.All) { if (final != XmlSchemaDerivationMethod.None) { if (final == XmlSchemaDerivationMethod.Restriction || final == XmlSchemaDerivationMethod.List || final == XmlSchemaDerivationMethod.Union) { this.finalResolved = base.Final; goto IL_19F; } base.error(h, "The value of final attribute is not valid for simpleType"); } XmlSchemaDerivationMethod xmlSchemaDerivationMethod = XmlSchemaDerivationMethod.Extension | XmlSchemaDerivationMethod.Restriction | XmlSchemaDerivationMethod.List | XmlSchemaDerivationMethod.Union; XmlSchemaDerivationMethod finalDefault = schema.FinalDefault; if (finalDefault != XmlSchemaDerivationMethod.All) { if (finalDefault != XmlSchemaDerivationMethod.None) { this.finalResolved = (schema.FinalDefault & xmlSchemaDerivationMethod); } else { this.finalResolved = XmlSchemaDerivationMethod.Empty; } } else { this.finalResolved = XmlSchemaDerivationMethod.All; } } else { this.finalResolved = XmlSchemaDerivationMethod.All; } } IL_19F: XmlSchemaUtil.CompileID(base.Id, this, schema.IDCollection, h); if (this.Content != null) { this.Content.OwnerType = this; } if (this.Content == null) { base.error(h, "Content is required in a simpletype"); } else if (this.Content is XmlSchemaSimpleTypeRestriction) { this.resolvedDerivedBy = XmlSchemaDerivationMethod.Restriction; this.errorCount += ((XmlSchemaSimpleTypeRestriction)this.Content).Compile(h, schema); } else if (this.Content is XmlSchemaSimpleTypeList) { this.resolvedDerivedBy = XmlSchemaDerivationMethod.List; this.errorCount += ((XmlSchemaSimpleTypeList)this.Content).Compile(h, schema); } else if (this.Content is XmlSchemaSimpleTypeUnion) { this.resolvedDerivedBy = XmlSchemaDerivationMethod.Union; this.errorCount += ((XmlSchemaSimpleTypeUnion)this.Content).Compile(h, schema); } this.CompilationId = schema.CompilationId; return(this.errorCount); }