private bool Contains(XmlSchemaDerivationMethod value) { XSComplexFinal enumValue = XSComplexFinal.FromNativeValue(value); IValue idx = _values.Find(enumValue); return(idx.DataType == DataType.Number); }
private bool Contains(XmlSchemaDerivationMethod _value) { XSSchemaFinal _enumValue = EnumerationXSSchemaFinal.FromNativeValue(_value); IValue _idx = _values.Find(_enumValue); return(_idx.DataType != DataType.Undefined); }
internal static bool IsDerivedFrom(object derivedType, object baseType, XmlSchemaDerivationMethod except) { if (derivedType == baseType) { return(true); } if (derivedType is XmlSchemaDatatype) { if ((except & XmlSchemaDerivationMethod.Restriction) != 0) { return(false); } return(IsDerivedFromDatatype(derivedType, baseType, except)); } else if (derivedType is XmlSchemaType) { XmlSchemaType derivedSchemaType = (XmlSchemaType)derivedType; XmlSchemaType baseSchemaType = baseType as XmlSchemaType; if (baseSchemaType != null) { return(IsDerivedFromBaseType(derivedSchemaType, baseSchemaType, except)); } else { if ((except & derivedSchemaType.DerivedBy) != 0) { return(false); } return(IsDerivedFromDatatype(derivedSchemaType.Datatype, baseType, except)); } } return(false); }
internal static XSComplexFinal FromNativeValue(XmlSchemaDerivationMethod native) { EnumerationXSComplexFinal enumeration = GlobalsManager.GetEnum <EnumerationXSComplexFinal>(); enumeration._valuesCache.TryGetValue(native, out XSComplexFinal value); return(value); }
private bool Contains(XmlSchemaDerivationMethod _value) { XSDisallowedSubstitutions _enumValue = EnumerationXSDisallowedSubstitutions.FromNativeValue(_value); IValue _idx = _values.Find(_enumValue); return(_idx.DataType != DataType.Undefined); }
private void ClearCompiledState() { this.attributeUses = null; this.localElements = null; this.attributeWildcard = null; this.contentTypeParticle = XmlSchemaParticle.Empty; this.blockResolved = XmlSchemaDerivationMethod.None; }
private void ClearCompiledState() { this.attributeUses = null; this.localElements = null; this.attributeWildcard = null; this.contentTypeParticle = XmlSchemaParticle.Empty; this.blockResolved = XmlSchemaDerivationMethod.None; }
internal override int Validate(ValidationEventHandler h, XmlSchema schema) { if (base.IsValidated(schema.ValidationId)) { return(this.errorCount); } if (this.recursed) { base.error(h, "Circular type reference was found."); return(this.errorCount); } this.recursed = true; this.CollectBaseType(h, schema); if (this.content != null) { this.errorCount += this.content.Validate(h, schema); } XmlSchemaSimpleType xmlSchemaSimpleType = base.BaseXmlSchemaType as XmlSchemaSimpleType; if (xmlSchemaSimpleType != null) { this.DatatypeInternal = xmlSchemaSimpleType.Datatype; } XmlSchemaSimpleType xmlSchemaSimpleType2 = base.BaseXmlSchemaType as XmlSchemaSimpleType; if (xmlSchemaSimpleType2 != null && (xmlSchemaSimpleType2.FinalResolved & this.resolvedDerivedBy) != XmlSchemaDerivationMethod.Empty) { base.error(h, "Specified derivation is prohibited by the base simple type."); } if (this.resolvedDerivedBy == XmlSchemaDerivationMethod.Restriction && xmlSchemaSimpleType2 != null) { this.variety = xmlSchemaSimpleType2.Variety; } else { this.variety = this.resolvedDerivedBy; } XmlSchemaSimpleTypeRestriction xmlSchemaSimpleTypeRestriction = this.Content as XmlSchemaSimpleTypeRestriction; object baseType = (base.BaseXmlSchemaType == null) ? base.Datatype : base.BaseXmlSchemaType; if (xmlSchemaSimpleTypeRestriction != null) { this.ValidateDerivationValid(baseType, xmlSchemaSimpleTypeRestriction.Facets, h, schema); } XmlSchemaSimpleTypeList xmlSchemaSimpleTypeList = this.Content as XmlSchemaSimpleTypeList; if (xmlSchemaSimpleTypeList != null) { XmlSchemaSimpleType xmlSchemaSimpleType3 = xmlSchemaSimpleTypeList.ValidatedListItemType as XmlSchemaSimpleType; if (xmlSchemaSimpleType3 != null && xmlSchemaSimpleType3.Content is XmlSchemaSimpleTypeList) { base.error(h, "List type must not be derived from another list type."); } } this.recursed = false; this.ValidationId = schema.ValidationId; return(this.errorCount); }
private void ClearCompiledState() { //Re-set post-compiled state for cloned object _attributeUses = null; _localElements = null; _attributeWildcard = null; _contentTypeParticle = XmlSchemaParticle.Empty; _blockResolved = XmlSchemaDerivationMethod.None; }
public XmlSchemaElement() { block = XmlSchemaDerivationMethod.None; final = XmlSchemaDerivationMethod.None; constraints = new XmlSchemaObjectCollection(); refName = XmlQualifiedName.Empty; schemaTypeName = XmlQualifiedName.Empty; substitutionGroup = XmlQualifiedName.Empty; InitPostCompileInformations (); }
// Is some value is read, return it. // If no values return empty. // If exception, return none public static XmlSchemaDerivationMethod ReadDerivationAttribute(XmlReader reader, out Exception innerExcpetion, string name, XmlSchemaDerivationMethod allowed) { innerExcpetion = null; try { string list = reader.Value; string warn = ""; XmlSchemaDerivationMethod val = 0; if (list.IndexOf("#all") != -1 && list.Trim() != "#all") { innerExcpetion = new Exception(list + " is not a valid value for " + name + ". #all if present must be the only value"); return(XmlSchemaDerivationMethod.All); } foreach (string xsdm in XmlSchemaUtil.SplitList(list)) { switch (xsdm) { case "": val = AddFlag(val, XmlSchemaDerivationMethod.Empty, allowed); break; case "#all": val = AddFlag(val, XmlSchemaDerivationMethod.All, allowed); break; case "substitution": val = AddFlag(val, XmlSchemaDerivationMethod.Substitution, allowed); break; case "extension": val = AddFlag(val, XmlSchemaDerivationMethod.Extension, allowed); break; case "restriction": val = AddFlag(val, XmlSchemaDerivationMethod.Restriction, allowed); break; case "list": val = AddFlag(val, XmlSchemaDerivationMethod.List, allowed); break; case "union": val = AddFlag(val, XmlSchemaDerivationMethod.Union, allowed); break; default: warn += xsdm + " "; break; } } if (warn != "") { innerExcpetion = new Exception(warn + "is/are not valid values for " + name); } return(val); } catch (Exception ex) { innerExcpetion = ex; return(XmlSchemaDerivationMethod.None); } }
private static XmlSchemaDerivationMethod AddFlag(XmlSchemaDerivationMethod dst, XmlSchemaDerivationMethod add, XmlSchemaDerivationMethod allowed) { if ((add & allowed) == XmlSchemaDerivationMethod.Empty && allowed != XmlSchemaDerivationMethod.All) { throw new ArgumentException(add + " is not allowed in this attribute."); } if ((dst & add) != XmlSchemaDerivationMethod.Empty) { throw new ArgumentException(add + " is already specified in this attribute."); } return(dst | add); }
internal bool ValidateTypeDerivationOK(object baseType, ValidationEventHandler h, XmlSchema schema, bool raiseError) { if (this == baseType || baseType == XmlSchemaSimpleType.AnySimpleType || baseType == XmlSchemaComplexType.AnyType) { return(true); } XmlSchemaSimpleType xmlSchemaSimpleType = baseType as XmlSchemaSimpleType; if (xmlSchemaSimpleType != null && (xmlSchemaSimpleType.FinalResolved & this.resolvedDerivedBy) != XmlSchemaDerivationMethod.Empty) { if (raiseError) { base.error(h, "Specified derivation is prohibited by the base type."); } return(false); } if (base.BaseXmlSchemaType == baseType || base.Datatype == baseType) { return(true); } XmlSchemaSimpleType xmlSchemaSimpleType2 = base.BaseXmlSchemaType as XmlSchemaSimpleType; if (xmlSchemaSimpleType2 != null && xmlSchemaSimpleType2.ValidateTypeDerivationOK(baseType, h, schema, false)) { return(true); } XmlSchemaDerivationMethod xmlSchemaDerivationMethod = this.Variety; if (xmlSchemaDerivationMethod == XmlSchemaDerivationMethod.List || xmlSchemaDerivationMethod == XmlSchemaDerivationMethod.Union) { if (baseType == XmlSchemaSimpleType.AnySimpleType) { return(true); } } if (xmlSchemaSimpleType != null && xmlSchemaSimpleType.Variety == XmlSchemaDerivationMethod.Union) { foreach (object baseType2 in ((XmlSchemaSimpleTypeUnion)xmlSchemaSimpleType.Content).ValidatedTypes) { if (this.ValidateTypeDerivationOK(baseType2, h, schema, false)) { return(true); } } } if (raiseError) { base.error(h, "Invalid simple type derivation was found."); } return(false); }
internal static XSSubstitutionGroupExclusions FromNativeValue(XmlSchemaDerivationMethod native) { switch (native) { case XmlSchemaDerivationMethod.All: case XmlSchemaDerivationMethod.Restriction: case XmlSchemaDerivationMethod.Extension: EnumerationXSSubstitutionGroupExclusions enumeration = GlobalsManager.GetEnum <EnumerationXSSubstitutionGroupExclusions>(); return(enumeration._valuesCache[native]); default: return(null); } }
internal void ValidateDerivationValid(object baseType, XmlSchemaObjectCollection facets, ValidationEventHandler h, XmlSchema schema) { XmlSchemaSimpleType xmlSchemaSimpleType = baseType as XmlSchemaSimpleType; XmlSchemaDerivationMethod xmlSchemaDerivationMethod = this.Variety; if (xmlSchemaDerivationMethod != XmlSchemaDerivationMethod.Restriction) { if (xmlSchemaDerivationMethod != XmlSchemaDerivationMethod.List) { if (xmlSchemaDerivationMethod == XmlSchemaDerivationMethod.Union) { if (facets != null) { foreach (XmlSchemaObject xmlSchemaObject in facets) { XmlSchemaFacet xmlSchemaFacet = (XmlSchemaFacet)xmlSchemaObject; if (!(xmlSchemaFacet is XmlSchemaEnumerationFacet) && !(xmlSchemaFacet is XmlSchemaPatternFacet)) { base.error(h, "Not allowed facet was found on this simple type which derives list type."); } } } } } else if (facets != null) { foreach (XmlSchemaObject xmlSchemaObject2 in facets) { XmlSchemaFacet xmlSchemaFacet2 = (XmlSchemaFacet)xmlSchemaObject2; if (!(xmlSchemaFacet2 is XmlSchemaLengthFacet) && !(xmlSchemaFacet2 is XmlSchemaMaxLengthFacet) && !(xmlSchemaFacet2 is XmlSchemaMinLengthFacet) && !(xmlSchemaFacet2 is XmlSchemaEnumerationFacet) && !(xmlSchemaFacet2 is XmlSchemaPatternFacet)) { base.error(h, "Not allowed facet was found on this simple type which derives list type."); } } } } else { if (xmlSchemaSimpleType != null && xmlSchemaSimpleType.resolvedDerivedBy != XmlSchemaDerivationMethod.Restriction) { base.error(h, "Base schema type is not either atomic type or primitive type."); } if (xmlSchemaSimpleType != null && (xmlSchemaSimpleType.FinalResolved & XmlSchemaDerivationMethod.Restriction) != XmlSchemaDerivationMethod.Empty) { base.error(h, "Derivation by restriction is prohibited by the base simple type."); } } }
public static XSSimpleFinal FromNativeValue(XmlSchemaDerivationMethod native) { switch (native) { case XmlSchemaDerivationMethod.All: case XmlSchemaDerivationMethod.Union: case XmlSchemaDerivationMethod.Restriction: case XmlSchemaDerivationMethod.List: EnumerationXSSimpleFinal enumeration = GlobalsManager.GetEnum <EnumerationXSSimpleFinal>(); return(enumeration._valuesCache[native]); default: return(null); } }
public XmlSchema () { attributeFormDefault= XmlSchemaForm.None; blockDefault = XmlSchemaDerivationMethod.None; elementFormDefault = XmlSchemaForm.None; finalDefault = XmlSchemaDerivationMethod.None; includes = new XmlSchemaObjectCollection(); isCompiled = false; items = new XmlSchemaObjectCollection(); attributeGroups = new XmlSchemaObjectTable(); attributes = new XmlSchemaObjectTable(); elements = new XmlSchemaObjectTable(); groups = new XmlSchemaObjectTable(); notations = new XmlSchemaObjectTable(); schemaTypes = new XmlSchemaObjectTable(); }
public static void AssertElementEx (XmlSchemaElement element, XmlSchemaDerivationMethod block, XmlSchemaDerivationMethod final, string defaultValue, string fixedValue, XmlSchemaForm form, bool isAbstract, bool isNillable, XmlQualifiedName substGroup) { Assert.IsNotNull (element); Assert.AreEqual (block, element.Block); Assert.AreEqual (final, element.Final); Assert.AreEqual (defaultValue, element.DefaultValue); Assert.AreEqual (fixedValue, element.FixedValue); Assert.AreEqual (form, element.Form); Assert.AreEqual (isAbstract, element.IsAbstract); Assert.AreEqual (isNillable, element.IsNillable); Assert.AreEqual (substGroup, element.SubstitutionGroup); }
public static void AssertElementEx(XmlSchemaElement element, XmlSchemaDerivationMethod block, XmlSchemaDerivationMethod final, string defaultValue, string fixedValue, XmlSchemaForm form, bool isAbstract, bool isNillable, XmlQualifiedName substGroup) { Assert.IsNotNull(element); Assert.AreEqual(block, element.Block); Assert.AreEqual(final, element.Final); Assert.AreEqual(defaultValue, element.DefaultValue); Assert.AreEqual(fixedValue, element.FixedValue); Assert.AreEqual(form, element.Form); Assert.AreEqual(isAbstract, element.IsAbstract); Assert.AreEqual(isNillable, element.IsNillable); Assert.AreEqual(substGroup, element.SubstitutionGroup); }
public XmlSchema() { attributeFormDefault = XmlSchemaForm.None; blockDefault = XmlSchemaDerivationMethod.None; elementFormDefault = XmlSchemaForm.None; finalDefault = XmlSchemaDerivationMethod.None; includes = new XmlSchemaObjectCollection(); isCompiled = false; items = new XmlSchemaObjectCollection(); attributeGroups = new XmlSchemaObjectTable(); attributes = new XmlSchemaObjectTable(); elements = new XmlSchemaObjectTable(); groups = new XmlSchemaObjectTable(); notations = new XmlSchemaObjectTable(); schemaTypes = new XmlSchemaObjectTable(); }
// Field generation private void GenerateAttributeField(XmlSchemaAttribute schemaAtt) { XmlSchemaDatatype primitive = schemaAtt.AttributeType as XmlSchemaDatatype; XmlSchemaSimpleType simple = schemaAtt.AttributeType as XmlSchemaSimpleType; XmlSchemaDerivationMethod deriv = XmlSchemaDerivationMethod.None; while (primitive == null) { if (simple == null) // maybe union { break; } primitive = simple.BaseSchemaType as XmlSchemaDatatype; if (primitive == null) { simple = simple.BaseSchemaType as XmlSchemaSimpleType; if (simple != null && simple.DerivedBy != XmlSchemaDerivationMethod.None) { deriv = simple.DerivedBy; } } } Type type = primitive != null ? primitive.ValueType : typeof(object); bool isList = (simple != null && simple.DerivedBy == XmlSchemaDerivationMethod.List); CodeTypeReference cType = new CodeTypeReference(type); cType.ArrayRank = isList ? 1 : 0; CodeMemberField cmf = CreateMemberField(cType, schemaAtt.QualifiedName.Name, XmlStructureType.Attribute); currentType.Members.Add(cmf); }
public static bool IsDerivedFrom(XmlSchemaType derivedType, XmlSchemaType baseType, XmlSchemaDerivationMethod except) { XmlSchemaSimpleType type; if ((derivedType == null) || (baseType == null)) { return false; } if (derivedType == baseType) { return true; } if (baseType == XmlSchemaComplexType.AnyType) { return true; } Label_0018: type = derivedType as XmlSchemaSimpleType; XmlSchemaSimpleType type2 = baseType as XmlSchemaSimpleType; if ((type2 != null) && (type != null)) { return ((type2 == DatatypeImplementation.AnySimpleType) || (((except & derivedType.DerivedBy) == XmlSchemaDerivationMethod.Empty) && type.Datatype.IsDerivedFrom(type2.Datatype))); } if ((except & derivedType.DerivedBy) == XmlSchemaDerivationMethod.Empty) { derivedType = derivedType.BaseXmlSchemaType; if (derivedType == baseType) { return true; } if (derivedType != null) { goto Label_0018; } } return false; }
private void ClearCompiledState() { //Re-set post-compiled state for cloned object _attributeUses = null; _localElements = null; _attributeWildcard = null; _contentTypeParticle = XmlSchemaParticle.Empty; _blockResolved = XmlSchemaDerivationMethod.None; }
private void CompileLocalAttributes(XmlSchemaComplexType baseType, XmlSchemaComplexType derivedType, XmlSchemaObjectCollection attributes, XmlSchemaAnyAttribute anyAttribute, XmlSchemaDerivationMethod derivedBy) { XmlSchemaAnyAttribute baseAttributeWildcard = baseType != null ? baseType.AttributeWildcard : null; for (int i = 0; i < attributes.Count; ++i) { XmlSchemaAttribute attr = attributes[i] as XmlSchemaAttribute; if (attr != null) { if (attr.Use != XmlSchemaUse.Prohibited) { CompileAttribute(attr); } if (attr.Use != XmlSchemaUse.Prohibited || (attr.Use == XmlSchemaUse.Prohibited && derivedBy == XmlSchemaDerivationMethod.Restriction && baseType != XmlSchemaComplexType.AnyType)) { if (derivedType.AttributeUses[attr.QualifiedName] == null) { derivedType.AttributeUses.Add(attr.QualifiedName, attr); } else { SendValidationEvent(Res.Sch_DupAttributeUse, attr.QualifiedName.ToString(), attr); } } else { SendValidationEvent(Res.Sch_AttributeIgnored, attr.QualifiedName.ToString(), attr, XmlSeverityType.Warning); } } else { // is XmlSchemaAttributeGroupRef XmlSchemaAttributeGroupRef attributeGroupRef = (XmlSchemaAttributeGroupRef) attributes[i]; XmlSchemaAttributeGroup attributeGroup = (XmlSchemaAttributeGroup)attributeGroups[attributeGroupRef.RefName]; if (attributeGroup != null) { CompileAttributeGroup(attributeGroup); foreach (XmlSchemaAttribute attribute in attributeGroup.AttributeUses.Values) { if (attribute.Use != XmlSchemaUse.Prohibited || (attribute.Use == XmlSchemaUse.Prohibited && derivedBy == XmlSchemaDerivationMethod.Restriction && baseType != XmlSchemaComplexType.AnyType)) { if (derivedType.AttributeUses[attribute.QualifiedName] == null) { derivedType.AttributeUses.Add(attribute.QualifiedName, attribute); } else { SendValidationEvent(Res.Sch_DupAttributeUse, attribute.QualifiedName.ToString(), attributeGroupRef); } } else { SendValidationEvent(Res.Sch_AttributeIgnored, attribute.QualifiedName.ToString(), attribute, XmlSeverityType.Warning); } } anyAttribute = CompileAnyAttributeIntersection(anyAttribute, attributeGroup.AttributeWildcard); } else { SendValidationEvent(Res.Sch_UndefAttributeGroupRef, attributeGroupRef.RefName.ToString(), attributeGroupRef); } } } // check derivation rules if (baseType != null) { if (derivedBy == XmlSchemaDerivationMethod.Extension) { derivedType.SetAttributeWildcard(CompileAnyAttributeUnion(anyAttribute, baseAttributeWildcard)); foreach(XmlSchemaAttribute attributeBase in baseType.AttributeUses.Values) { XmlSchemaAttribute attribute = (XmlSchemaAttribute)derivedType.AttributeUses[attributeBase.QualifiedName]; if (attribute == null) { derivedType.AttributeUses.Add(attributeBase.QualifiedName, attributeBase); } else { Debug.Assert(attribute.Use != XmlSchemaUse.Prohibited); if (attributeBase.Use != XmlSchemaUse.Prohibited && attribute.AttributeSchemaType != attributeBase.AttributeSchemaType) { //Extension allows previously prohibited attributes to be re-added, SendValidationEvent(Res.Sch_InvalidAttributeExtension, attribute); } } } } else { // derivedBy == XmlSchemaDerivationMethod.Restriction // Schema Component Constraint: Derivation Valid (Restriction, Complex) if ((anyAttribute != null) && (baseAttributeWildcard == null || !XmlSchemaAnyAttribute.IsSubset(anyAttribute, baseAttributeWildcard) || !IsProcessContentsRestricted(baseType, anyAttribute, baseAttributeWildcard)) ) { SendValidationEvent(Res.Sch_InvalidAnyAttributeRestriction, derivedType); } else { derivedType.SetAttributeWildcard(anyAttribute); //complete wildcard } // Add form the base foreach(XmlSchemaAttribute attributeBase in baseType.AttributeUses.Values) { XmlSchemaAttribute attribute = (XmlSchemaAttribute)derivedType.AttributeUses[attributeBase.QualifiedName]; if (attribute == null) { derivedType.AttributeUses.Add(attributeBase.QualifiedName, attributeBase); } else { if (attributeBase.Use == XmlSchemaUse.Prohibited && attribute.Use != XmlSchemaUse.Prohibited) { #if DEBUG string position = string.Empty; if (derivedType.SourceUri != null) { position = " in " + derivedType.SourceUri + "(" + derivedType.LineNumber + ", " + derivedType.LinePosition + ")"; } Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, "Invalid complexType attributes restriction" + position); Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, " Base " + DumpAttributes(baseType.AttributeUses, baseType.AttributeWildcard)); Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, " Derived " + DumpAttributes(derivedType.AttributeUses, derivedType.AttributeWildcard)); #endif SendValidationEvent(Res.Sch_AttributeRestrictionProhibited, attribute); } else if (attributeBase.Use == XmlSchemaUse.Required && (attribute.Use != XmlSchemaUse.Required)) { //If base is required, derived should also be required SendValidationEvent(Res.Sch_AttributeUseInvalid, attribute); } else if (attribute.Use == XmlSchemaUse.Prohibited) { continue; } else if (attributeBase.AttributeSchemaType == null || attribute.AttributeSchemaType == null || !XmlSchemaType.IsDerivedFrom(attribute.AttributeSchemaType, attributeBase.AttributeSchemaType, XmlSchemaDerivationMethod.Empty)) { SendValidationEvent(Res.Sch_AttributeRestrictionInvalid, attribute); } else if (!IsFixedEqual(attributeBase.AttDef, attribute.AttDef)) { SendValidationEvent(Res.Sch_AttributeFixedInvalid, attribute); } } } // Check additional ones are valid restriction of base's wildcard foreach(XmlSchemaAttribute attribute in derivedType.AttributeUses.Values) { XmlSchemaAttribute attributeBase = (XmlSchemaAttribute)baseType.AttributeUses[attribute.QualifiedName]; if (attributeBase != null) { continue; } if (baseAttributeWildcard == null || !baseAttributeWildcard.Allows(attribute.QualifiedName)) { #if DEBUG string position = string.Empty; if (derivedType.SourceUri != null) { position = " in " + derivedType.SourceUri + "(" + derivedType.LineNumber + ", " + derivedType.LinePosition + ")"; } Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, "Invalid complexType attributes restriction" + position); Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, " Base " + DumpAttributes(baseType.AttributeUses, baseType.AttributeWildcard)); Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, " Derived " + DumpAttributes(derivedType.AttributeUses, derivedType.AttributeWildcard)); #endif SendValidationEvent(Res.Sch_AttributeRestrictionInvalidFromWildcard, attribute); } } } } else { derivedType.SetAttributeWildcard(anyAttribute); } }
private static bool IsDerivedFromBaseType(XmlSchemaType derivedType, XmlSchemaType baseType, XmlSchemaDerivationMethod except) { do { if ((except & derivedType.DerivedBy) != 0) { return false; } object[] types = derivedType.BaseSchemaType as object[]; if (types != null) { // union foreach (object type in types) { if (IsDerivedFrom(type, baseType, except)) { return true; } } return false; } derivedType = derivedType.BaseSchemaType as XmlSchemaType; if (derivedType == baseType) { return true; } } while(derivedType != null); return false; }
internal override int Validate(ValidationEventHandler h, XmlSchema schema) { // 3.14.6 Properties Correct. // // 1. Post Compilation Properties // {name}, {target namespace} => QNameInternal. Already Compile()d. // {base type definition} => baseSchemaTypeInternal // {final} => finalResolved. Already Compile()d. // {variety} => resolvedDerivedBy. Already Compile()d. // // 2. Should be checked by "recursed" field. if (IsValidated(schema.ValidationId)) { return(errorCount); } if (recursed) { error(h, "Circular type reference was found."); return(errorCount); } recursed = true; CollectBaseType(h, schema); if (content != null) { errorCount += content.Validate(h, schema); } /* * // BaseSchemaType property * BaseXmlSchemaTypeInternal = content.ActualBaseSchemaType as XmlSchemaType; * if (this.BaseXmlSchemaTypeInternal == null) * this.DatatypeInternal = content.ActualBaseSchemaType as XmlSchemaDatatype; */ // Datatype property XmlSchemaSimpleType simple = BaseXmlSchemaType as XmlSchemaSimpleType; if (simple != null) { this.DatatypeInternal = simple.Datatype; } // else // DatatypeInternal = BaseSchemaType as XmlSchemaDatatype; // 3. XmlSchemaSimpleType baseSType = BaseXmlSchemaType as XmlSchemaSimpleType; if (baseSType != null) { if ((baseSType.FinalResolved & this.resolvedDerivedBy) != 0) { error(h, "Specified derivation is prohibited by the base simple type."); } } // {variety} if (this.resolvedDerivedBy == XmlSchemaDerivationMethod.Restriction && baseSType != null) { this.variety = baseSType.Variety; } else { this.variety = this.resolvedDerivedBy; } // 3.14.6 Derivation Valid (Restriction, Simple) XmlSchemaSimpleTypeRestriction r = Content as XmlSchemaSimpleTypeRestriction; object baseType = BaseXmlSchemaType != null ? (object)BaseXmlSchemaType : Datatype; if (r != null) { ValidateDerivationValid(baseType, r.Facets, h, schema); } // TODO: describe which validation term this belongs to. XmlSchemaSimpleTypeList l = Content as XmlSchemaSimpleTypeList; if (l != null) { XmlSchemaSimpleType itemSimpleType = l.ValidatedListItemType as XmlSchemaSimpleType; if (itemSimpleType != null && itemSimpleType.Content is XmlSchemaSimpleTypeList) { error(h, "List type must not be derived from another list type."); } } recursed = false; ValidationId = schema.ValidationId; return(errorCount); }
private void SetSchemaDefaults(XmlSchema schema) { if (schema.BlockDefault == XmlSchemaDerivationMethod.All) { this.blockDefault = XmlSchemaDerivationMethod.All; } else if (schema.BlockDefault == XmlSchemaDerivationMethod.None) { this.blockDefault = XmlSchemaDerivationMethod.Empty; } else { if ((schema.BlockDefault & ~schemaBlockDefaultAllowed) != 0) { SendValidationEvent(Res.Sch_InvalidBlockDefaultValue, schema); } this.blockDefault = schema.BlockDefault & schemaBlockDefaultAllowed; } if (schema.FinalDefault == XmlSchemaDerivationMethod.All) { this.finalDefault = XmlSchemaDerivationMethod.All; } else if (schema.FinalDefault == XmlSchemaDerivationMethod.None) { this.finalDefault = XmlSchemaDerivationMethod.Empty; } else { if ((schema.FinalDefault & ~schemaFinalDefaultAllowed) != 0) { SendValidationEvent(Res.Sch_InvalidFinalDefaultValue, schema); } this.finalDefault = schema.FinalDefault & schemaFinalDefaultAllowed; } this.elementFormDefault = schema.ElementFormDefault; if (this.elementFormDefault == XmlSchemaForm.None) { this.elementFormDefault = XmlSchemaForm.Unqualified; } this.attributeFormDefault = schema.AttributeFormDefault; if (this.attributeFormDefault == XmlSchemaForm.None) { this.attributeFormDefault = XmlSchemaForm.Unqualified; } }
private static XmlSchemaDerivationMethod AddFlag (XmlSchemaDerivationMethod dst, XmlSchemaDerivationMethod add, XmlSchemaDerivationMethod allowed) { if ((add & allowed) == 0 && allowed != XmlSchemaDerivationMethod.All) throw new ArgumentException (add + " is not allowed in this attribute."); if ((dst & add) != 0) throw new ArgumentException (add + " is already specified in this attribute."); return dst | add; }
private void CompileLocalAttributes(XmlSchemaComplexType baseType, XmlSchemaComplexType derivedType, XmlSchemaObjectCollection attributes, XmlSchemaAnyAttribute anyAttribute, XmlSchemaDerivationMethod derivedBy) { XmlSchemaAnyAttribute b = (baseType != null) ? baseType.AttributeWildcard : null; for (int i = 0; i < attributes.Count; i++) { XmlSchemaAttribute xa = attributes[i] as XmlSchemaAttribute; if (xa != null) { if (xa.Use != XmlSchemaUse.Prohibited) { this.CompileAttribute(xa); } if ((xa.Use != XmlSchemaUse.Prohibited) || (((xa.Use == XmlSchemaUse.Prohibited) && (derivedBy == XmlSchemaDerivationMethod.Restriction)) && (baseType != XmlSchemaComplexType.AnyType))) { if (derivedType.AttributeUses[xa.QualifiedName] == null) { derivedType.AttributeUses.Add(xa.QualifiedName, xa); } else { base.SendValidationEvent("Sch_DupAttributeUse", xa.QualifiedName.ToString(), xa); } } else { base.SendValidationEvent("Sch_AttributeIgnored", xa.QualifiedName.ToString(), xa, XmlSeverityType.Warning); } } else { XmlSchemaAttributeGroupRef source = (XmlSchemaAttributeGroupRef) attributes[i]; XmlSchemaAttributeGroup attributeGroup = (XmlSchemaAttributeGroup) this.schema.AttributeGroups[source.RefName]; if (attributeGroup != null) { this.CompileAttributeGroup(attributeGroup); foreach (XmlSchemaAttribute attribute3 in attributeGroup.AttributeUses.Values) { if ((attribute3.Use != XmlSchemaUse.Prohibited) || (((attribute3.Use == XmlSchemaUse.Prohibited) && (derivedBy == XmlSchemaDerivationMethod.Restriction)) && (baseType != XmlSchemaComplexType.AnyType))) { if (derivedType.AttributeUses[attribute3.QualifiedName] == null) { derivedType.AttributeUses.Add(attribute3.QualifiedName, attribute3); } else { base.SendValidationEvent("Sch_DupAttributeUse", attribute3.QualifiedName.ToString(), source); } } else { base.SendValidationEvent("Sch_AttributeIgnored", attribute3.QualifiedName.ToString(), attribute3, XmlSeverityType.Warning); } } anyAttribute = this.CompileAnyAttributeIntersection(anyAttribute, attributeGroup.AttributeWildcard); } else { base.SendValidationEvent("Sch_UndefAttributeGroupRef", source.RefName.ToString(), source); } } } if (baseType != null) { if (derivedBy == XmlSchemaDerivationMethod.Extension) { derivedType.SetAttributeWildcard(this.CompileAnyAttributeUnion(anyAttribute, b)); foreach (XmlSchemaAttribute attribute4 in baseType.AttributeUses.Values) { XmlSchemaAttribute attribute5 = (XmlSchemaAttribute) derivedType.AttributeUses[attribute4.QualifiedName]; if (attribute5 != null) { if ((attribute5.AttributeSchemaType != attribute4.AttributeSchemaType) || (attribute4.Use == XmlSchemaUse.Prohibited)) { base.SendValidationEvent("Sch_InvalidAttributeExtension", attribute5); } } else { derivedType.AttributeUses.Add(attribute4.QualifiedName, attribute4); } } } else { if ((anyAttribute != null) && ((b == null) || !XmlSchemaAnyAttribute.IsSubset(anyAttribute, b))) { base.SendValidationEvent("Sch_InvalidAnyAttributeRestriction", derivedType); } else { derivedType.SetAttributeWildcard(anyAttribute); } foreach (XmlSchemaAttribute attribute6 in baseType.AttributeUses.Values) { XmlSchemaAttribute attribute7 = (XmlSchemaAttribute) derivedType.AttributeUses[attribute6.QualifiedName]; if (attribute7 == null) { derivedType.AttributeUses.Add(attribute6.QualifiedName, attribute6); } else if ((attribute6.Use == XmlSchemaUse.Prohibited) && (attribute7.Use != XmlSchemaUse.Prohibited)) { base.SendValidationEvent("Sch_AttributeRestrictionProhibited", attribute7); } else if ((attribute7.Use != XmlSchemaUse.Prohibited) && (((attribute6.AttributeSchemaType == null) || (attribute7.AttributeSchemaType == null)) || !XmlSchemaType.IsDerivedFrom(attribute7.AttributeSchemaType, attribute6.AttributeSchemaType, XmlSchemaDerivationMethod.Empty))) { base.SendValidationEvent("Sch_AttributeRestrictionInvalid", attribute7); } } foreach (XmlSchemaAttribute attribute8 in derivedType.AttributeUses.Values) { if ((((XmlSchemaAttribute) baseType.AttributeUses[attribute8.QualifiedName]) == null) && ((b == null) || !b.Allows(attribute8.QualifiedName))) { base.SendValidationEvent("Sch_AttributeRestrictionInvalidFromWildcard", attribute8); } } } } else { derivedType.SetAttributeWildcard(anyAttribute); } }
/// <summary>Initializes a new instance of the <see cref="T:System.Xml.Schema.XmlSchemaType" /> class.</summary> public XmlSchemaType() { this.final = XmlSchemaDerivationMethod.None; this.QNameInternal = XmlQualifiedName.Empty; }
/// <summary>Returns a value indicating if the derived schema type specified is derived from the base schema type specified</summary> /// <returns>true if the derived type is derived from the base type; otherwise, false.</returns> /// <param name="derivedType">The derived <see cref="T:System.Xml.Schema.XmlSchemaType" /> to test.</param> /// <param name="baseType">The base <see cref="T:System.Xml.Schema.XmlSchemaType" /> to test the derived <see cref="T:System.Xml.Schema.XmlSchemaType" /> against.</param> /// <param name="except">One of the <see cref="T:System.Xml.Schema.XmlSchemaDerivationMethod" /> values representing a type derivation method to exclude from testing.</param> public static bool IsDerivedFrom(XmlSchemaType derivedType, XmlSchemaType baseType, XmlSchemaDerivationMethod except) { return(derivedType.BaseXmlSchemaType != null && (derivedType.DerivedBy & except) == XmlSchemaDerivationMethod.Empty && (derivedType.BaseXmlSchemaType == baseType || XmlSchemaType.IsDerivedFrom(derivedType.BaseXmlSchemaType, baseType, except))); }
private void Preprocess(XmlSchema schema, string targetNamespace, Compositor compositor) { if (schema.IsProcessing) { return; } schema.IsProcessing = true; string tns = schema.TargetNamespace; if (tns != null) { schema.TargetNamespace = tns = NameTable.Add(tns); if (tns.Length == 0) { SendValidationEvent(Res.Sch_InvalidTargetNamespaceAttribute, schema); } else { try { XmlConvert.ToUri(tns); // can throw } catch { SendValidationEvent(Res.Sch_InvalidNamespace, schema.TargetNamespace, schema); } } } if (schema.Version != null) { try { XmlConvert.VerifyTOKEN(schema.Version); // can throw } catch (Exception) { SendValidationEvent(Res.Sch_AttributeValueDataType, "version", schema); } } switch (compositor) { case Compositor.Root: if (targetNamespace == null && schema.TargetNamespace != null) { // not specified targetNamespace = schema.TargetNamespace; } else if (schema.TargetNamespace == null && targetNamespace != null && targetNamespace.Length == 0) { // no namespace schema targetNamespace = null; } if (targetNamespace != schema.TargetNamespace) { SendValidationEvent(Res.Sch_MismatchTargetNamespaceEx, targetNamespace, schema.TargetNamespace, schema); } break; case Compositor.Import: if (targetNamespace != schema.TargetNamespace) { SendValidationEvent(Res.Sch_MismatchTargetNamespaceImport, targetNamespace, schema.TargetNamespace, schema); } break; case Compositor.Include: if (schema.TargetNamespace != null) { if (targetNamespace != schema.TargetNamespace) { SendValidationEvent(Res.Sch_MismatchTargetNamespaceInclude, targetNamespace, schema.TargetNamespace, schema); } } break; } for (int i = 0; i < schema.Includes.Count; ++i) { XmlSchemaExternal include = (XmlSchemaExternal)schema.Includes[i]; SetParent(include, schema); PreprocessAnnotation(include); string loc = include.SchemaLocation; if (loc != null) { try { XmlConvert.ToUri(loc); // can throw } catch { SendValidationEvent(Res.Sch_InvalidSchemaLocation, loc, include); } } else if((include is XmlSchemaRedefine || include is XmlSchemaInclude) && include.Schema == null) { SendValidationEvent(Res.Sch_MissRequiredAttribute, "schemaLocation", include); } if (include.Schema != null) { if (include is XmlSchemaRedefine) { Preprocess(include.Schema, schema.TargetNamespace, Compositor.Include); } else if (include is XmlSchemaImport) { if (((XmlSchemaImport)include).Namespace == null && schema.TargetNamespace == null) { SendValidationEvent(Res.Sch_ImportTargetNamespaceNull, include); } else if (((XmlSchemaImport)include).Namespace == schema.TargetNamespace) { SendValidationEvent(Res.Sch_ImportTargetNamespace, include); } Preprocess(include.Schema, ((XmlSchemaImport)include).Namespace, Compositor.Import); } else { Preprocess(include.Schema, schema.TargetNamespace, Compositor.Include); } } else if (include is XmlSchemaImport) { string ns = ((XmlSchemaImport)include).Namespace; if (ns != null) { if (ns.Length == 0) { SendValidationEvent(Res.Sch_InvalidNamespaceAttribute, ns, include); } else { try { XmlConvert.ToUri(ns); //can throw } catch(FormatException) { SendValidationEvent(Res.Sch_InvalidNamespace, ns, include); } } } } } //Begin processing the current schema passed to preprocess //Build the namespaces that can be referenced in the current schema BuildRefNamespaces(schema); this.targetNamespace = targetNamespace == null ? string.Empty : targetNamespace; if (schema.BlockDefault == XmlSchemaDerivationMethod.All) { this.blockDefault = XmlSchemaDerivationMethod.All; } else if (schema.BlockDefault == XmlSchemaDerivationMethod.None) { this.blockDefault = XmlSchemaDerivationMethod.Empty; } else { if ((schema.BlockDefault & ~schemaBlockDefaultAllowed) != 0) { SendValidationEvent(Res.Sch_InvalidBlockDefaultValue, schema); } this.blockDefault = schema.BlockDefault & schemaBlockDefaultAllowed; } if (schema.FinalDefault == XmlSchemaDerivationMethod.All) { this.finalDefault = XmlSchemaDerivationMethod.All; } else if (schema.FinalDefault == XmlSchemaDerivationMethod.None) { this.finalDefault = XmlSchemaDerivationMethod.Empty; } else { if ((schema.FinalDefault & ~schemaFinalDefaultAllowed) != 0) { SendValidationEvent(Res.Sch_InvalidFinalDefaultValue, schema); } this.finalDefault = schema.FinalDefault & schemaFinalDefaultAllowed; } this.elementFormDefault = schema.ElementFormDefault; if (this.elementFormDefault == XmlSchemaForm.None) { this.elementFormDefault = XmlSchemaForm.Unqualified; } this.attributeFormDefault = schema.AttributeFormDefault; if (this.attributeFormDefault == XmlSchemaForm.None) { this.attributeFormDefault = XmlSchemaForm.Unqualified; } for (int i = 0; i < schema.Includes.Count; ++i) { XmlSchemaExternal include = (XmlSchemaExternal)schema.Includes[i]; if (include is XmlSchemaRedefine) { XmlSchemaRedefine redefine = (XmlSchemaRedefine)include; if (include.Schema != null) { PreprocessRedefine(redefine); } else { for (int j = 0; j < redefine.Items.Count; ++j) { if (!(redefine.Items[j] is XmlSchemaAnnotation)) { SendValidationEvent(Res.Sch_RedefineNoSchema, redefine); break; } } } } XmlSchema includedSchema = include.Schema; if (includedSchema != null) { foreach (XmlSchemaElement element in includedSchema.Elements.Values) { AddToTable(schema.Elements, element.QualifiedName, element); } foreach (XmlSchemaAttribute attribute in includedSchema.Attributes.Values) { AddToTable(schema.Attributes, attribute.QualifiedName, attribute); } foreach (XmlSchemaGroup group in includedSchema.Groups.Values) { AddToTable(schema.Groups, group.QualifiedName, group); } foreach (XmlSchemaAttributeGroup attributeGroup in includedSchema.AttributeGroups.Values) { AddToTable(schema.AttributeGroups, attributeGroup.QualifiedName, attributeGroup); } foreach (XmlSchemaType type in includedSchema.SchemaTypes.Values) { AddToTable(schema.SchemaTypes, type.QualifiedName, type); } foreach (XmlSchemaNotation notation in includedSchema.Notations.Values) { AddToTable(schema.Notations, notation.QualifiedName, notation); } } ValidateIdAttribute(include); } List<XmlSchemaObject> removeItemsList = new List<XmlSchemaObject>(); for (int i = 0; i < schema.Items.Count; ++i) { SetParent(schema.Items[i], schema); XmlSchemaAttribute attribute = schema.Items[i] as XmlSchemaAttribute; if (attribute != null) { PreprocessAttribute(attribute); AddToTable(schema.Attributes, attribute.QualifiedName, attribute); } else if (schema.Items[i] is XmlSchemaAttributeGroup) { XmlSchemaAttributeGroup attributeGroup = (XmlSchemaAttributeGroup)schema.Items[i]; PreprocessAttributeGroup(attributeGroup); AddToTable(schema.AttributeGroups, attributeGroup.QualifiedName, attributeGroup); } else if (schema.Items[i] is XmlSchemaComplexType) { XmlSchemaComplexType complexType = (XmlSchemaComplexType)schema.Items[i]; PreprocessComplexType(complexType, false); AddToTable(schema.SchemaTypes, complexType.QualifiedName, complexType); } else if (schema.Items[i] is XmlSchemaSimpleType) { XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)schema.Items[i]; PreprocessSimpleType(simpleType, false); AddToTable(schema.SchemaTypes, simpleType.QualifiedName, simpleType); } else if (schema.Items[i] is XmlSchemaElement) { XmlSchemaElement element = (XmlSchemaElement)schema.Items[i]; PreprocessElement(element); AddToTable(schema.Elements, element.QualifiedName, element); } else if (schema.Items[i] is XmlSchemaGroup) { XmlSchemaGroup group = (XmlSchemaGroup)schema.Items[i]; PreprocessGroup(group); AddToTable(schema.Groups, group.QualifiedName, group); } else if (schema.Items[i] is XmlSchemaNotation) { XmlSchemaNotation notation = (XmlSchemaNotation)schema.Items[i]; PreprocessNotation(notation); AddToTable(schema.Notations, notation.QualifiedName, notation); } else if(!(schema.Items[i] is XmlSchemaAnnotation)) { SendValidationEvent(Res.Sch_InvalidCollection, schema.Items[i]); removeItemsList.Add(schema.Items[i]); } } for (int i = 0; i < removeItemsList.Count; ++i) { schema.Items.Remove(removeItemsList[i]); } schema.IsProcessing = false; }
public XmlSchemaComplexType () { attributes = new XmlSchemaObjectCollection(); block = XmlSchemaDerivationMethod.None; attributeUses = new XmlSchemaObjectTable(); validatableParticle = XmlSchemaParticle.Empty; contentTypeParticle = validatableParticle; }
/// <remarks> /// 1. If ContentModel is present, neither particle nor Attributes nor AnyAttribute can be present. /// 2. If particle is present, /// a. For a topLevelComplexType /// 1. name must be present and type NCName /// 2. if block is #all, blockdefault is #all, else List of (extension | restriction) /// 3. if final is #all, finaldefault is #all, else List of (extension | restriction) /// b. For a local Complex type /// 1. abstract must be false /// 2. Name must be absent /// 3. final must be absent /// 4. block must be absent /// /// </remarks> internal override int Compile (ValidationEventHandler h, XmlSchema schema) { // If this is already compiled this time, simply skip. if (CompilationId == schema.CompilationId) return errorCount; ValidatedIsAbstract = isAbstract; attributeUses.Clear(); if (isRedefinedComponent) { if (Annotation != null) Annotation.isRedefinedComponent = true; if (AnyAttribute != null) AnyAttribute.isRedefinedComponent = true; foreach (XmlSchemaObject obj in Attributes) obj.isRedefinedComponent = true; if (ContentModel != null) ContentModel.isRedefinedComponent = true; if (Particle != null) Particle.isRedefinedComponent = true; } // block/final resolution if(ParentIsSchema || isRedefineChild) { if(this.Name == null || this.Name == string.Empty) error(h,"name must be present in a top level complex type"); else if(!XmlSchemaUtil.CheckNCName(Name)) error(h,"name must be a NCName"); else this.QNameInternal = new XmlQualifiedName(Name, AncestorSchema.TargetNamespace); if(Block != XmlSchemaDerivationMethod.None) { if(Block == XmlSchemaDerivationMethod.All) { blockResolved = XmlSchemaDerivationMethod.All; } else { if ((Block & XmlSchemaUtil.ComplexTypeBlockAllowed) != Block) error (h, "Invalid block specification."); blockResolved = Block & XmlSchemaUtil.ComplexTypeBlockAllowed; } } else { switch (schema.BlockDefault) { case XmlSchemaDerivationMethod.All: blockResolved = XmlSchemaDerivationMethod.All; break; case XmlSchemaDerivationMethod.None: blockResolved = XmlSchemaDerivationMethod.Empty; break; default: blockResolved = schema.BlockDefault & XmlSchemaUtil.ComplexTypeBlockAllowed; break; } } if(Final != XmlSchemaDerivationMethod.None) { if(Final == XmlSchemaDerivationMethod.All) finalResolved = XmlSchemaDerivationMethod.All; else if ((Final & XmlSchemaUtil.FinalAllowed) != Final) error (h, "Invalid final specification."); else finalResolved = Final; } else { switch (schema.FinalDefault) { case XmlSchemaDerivationMethod.All: finalResolved = XmlSchemaDerivationMethod.All; break; case XmlSchemaDerivationMethod.None: finalResolved = XmlSchemaDerivationMethod.Empty; break; default: finalResolved = schema.FinalDefault & XmlSchemaUtil.FinalAllowed; break; } } } else // Not Top Level { if(isAbstract) error(h,"abstract must be false in a local complex type"); if(Name != null) error(h,"name must be absent in a local complex type"); if(Final != XmlSchemaDerivationMethod.None) error(h,"final must be absent in a local complex type"); if(block != XmlSchemaDerivationMethod.None) error(h,"block must be absent in a local complex type"); } // Process contents and BaseSchemaType if(contentModel != null) { if(anyAttribute != null || Attributes.Count != 0 || Particle != null) error(h,"attributes, particles or anyattribute is not allowed if ContentModel is present"); errorCount += contentModel.Compile (h, schema); XmlSchemaSimpleContent smodel = ContentModel as XmlSchemaSimpleContent; if(smodel != null) { XmlSchemaSimpleContentExtension sscx = smodel.Content as XmlSchemaSimpleContentExtension; if (sscx == null) { XmlSchemaSimpleContentRestriction sscr = smodel.Content as XmlSchemaSimpleContentRestriction; if (sscr != null) { if (sscr.BaseType != null) { sscr.BaseType.Compile (h, schema); BaseXmlSchemaTypeInternal = sscr.BaseType; } } } } } else { if (Particle != null) errorCount += Particle.Compile (h, schema); if(this.anyAttribute != null) { 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 atgrp = (XmlSchemaAttributeGroupRef) obj; errorCount += atgrp.Compile(h,schema); } else error(h,obj.GetType() +" is not valid in this place::ComplexType"); } } XmlSchemaUtil.CompileID(Id, this, schema.IDCollection, h); this.CompilationId = schema.CompilationId; return errorCount; }
internal void SetDerivedBy(XmlSchemaDerivationMethod value) { derivedBy = value; }
private void TraverseParticle(XmlSchemaParticle particle, XmlSchemaComplexType baseType, ClrContentTypeInfo typeInfo, XmlSchemaDerivationMethod derivationMethod) { if (particleStack == null) { particleStack = new Stack <ParticleData>(); } else { particleStack.Clear(); } if (propertyNameTypeTable == null) { propertyNameTypeTable = new Dictionary <string, ClrPropertyInfo>(); } else { propertyNameTypeTable.Clear(); } XmlSchemaParticle baseParticle = baseType.ContentTypeParticle; ParticleData particleData; GroupingInfo parentGroupInfo = null; StringBuilder regEx = new StringBuilder(); XmlSchemaGroupBase currentGroupBase = null; GroupingInfo currentGroupingInfo = null; int currentIndex = 0; while (true) { // dont interrogate a particle if we are past the end of the list if (currentGroupBase == null || currentIndex <= currentGroupBase.Items.Count) { ParticleType particleType = particle.GetParticleType(); switch (particleType) { case ParticleType.Element: { XmlSchemaElement elem = particle as XmlSchemaElement; ClrPropertyInfo propertyInfo = null; bool fromBaseType = false; if (derivationMethod == XmlSchemaDerivationMethod.Extension && typeInfo.IsDerived) { if (baseParticle.ContainsElement(elem)) { fromBaseType = true; } else if (!typeInfo.InlineBaseType && baseType.ContainsName(elem.QualifiedName)) { typeInfo.InlineBaseType = true; } } propertyInfo = BuildProperty(elem, fromBaseType); regEx.Append(propertyInfo.PropertyName); AppendOccurenceToRegex(propertyInfo, regEx); //Add to parent if (currentGroupingInfo == null) { //Not adding property to propertyNameTypeTable as this case will occur only for pointless groups, so they have just one property BuildAnnotationInformation(propertyInfo, elem, false, false); typeInfo.AddMember(propertyInfo); } else { BuildAnnotationInformation(propertyInfo, elem, currentGroupingInfo.ContentModelType == ContentModelType.Choice, currentGroupingInfo.IsNested); currentGroupingInfo.AddChild(propertyInfo); SetPropertyFlags(propertyInfo, currentGroupingInfo, elem.ElementSchemaType); } break; } case ParticleType.Any: { regEx.Append("any"); XmlSchemaAny any = particle as XmlSchemaAny; if (derivationMethod == XmlSchemaDerivationMethod.Extension && typeInfo.IsDerived) { if (baseParticle.ContainsWildCard(any)) { typeInfo.HasElementWildCard = true; //ANY property in the base type will be reused } } //Note we always create a property info object to keep the original nesting structure in the schema //so it can be used to create a correct FSM; on the other hand, typeInfo.HasElementWildCard will indicate whether //we need to create a property in the resulting object type. ClrWildCardPropertyInfo wcPropertyInfo = BuildAnyProperty(any, !typeInfo.HasElementWildCard); //Add to parent if (currentGroupingInfo == null) { typeInfo.AddMember(wcPropertyInfo); } else { currentGroupingInfo.AddChild(wcPropertyInfo); } if (!typeInfo.HasElementWildCard) { typeInfo.HasElementWildCard = true; } break; } case ParticleType.Sequence: case ParticleType.Choice: case ParticleType.All: regEx.Append("("); if (currentGroupBase != null) { //already there is a group that we are processing, push it on stack to process sub-group particleStack.Push( new ParticleData(currentGroupBase, currentGroupingInfo, currentIndex)); currentIndex = 0; //Re-start index for new group base } parentGroupInfo = currentGroupingInfo; //Assign parent before creating child groupInfo currentGroupBase = particle as XmlSchemaGroupBase; Debug.Assert(currentGroupBase != null); currentGroupingInfo = new GroupingInfo((ContentModelType)((int)particleType), GetOccurence(currentGroupBase)); //Add to parent if (parentGroupInfo == null) { typeInfo.AddMember(currentGroupingInfo); parentGroupInfo = currentGroupingInfo; //Assign first time } else { parentGroupInfo.AddChild(currentGroupingInfo); parentGroupInfo.HasChildGroups = true; currentGroupingInfo.IsNested = true; if (parentGroupInfo.IsRepeating) { currentGroupingInfo.IsRepeating = true; } if (currentGroupingInfo.IsRepeating) { parentGroupInfo.HasRepeatingGroups = true; } } break; } } //Drill down into items if (currentGroupBase != null && currentIndex < currentGroupBase.Items.Count) { // if this isnt the first, then we need a seperator if (currentIndex > 0) { regEx.Append(currentGroupingInfo.ContentModelType == ContentModelType.Choice ? " | " : ", "); } particle = (XmlSchemaParticle)currentGroupBase.Items[currentIndex++]; } else { if (currentGroupBase != null) { regEx.Append(")"); AppendOccurenceToRegex(currentGroupingInfo, regEx); } if (particleStack.Count > 0) { bool childGroupHasRecurringElements = currentGroupingInfo.HasRecurrentElements; bool childGroupHasRepeatingGroups = currentGroupingInfo.HasRepeatingGroups; particleData = particleStack.Pop(); currentGroupBase = particleData.currentGroupBase; currentGroupingInfo = particleData.currentGroupingInfo; currentGroupingInfo.HasRecurrentElements = childGroupHasRecurringElements; currentGroupingInfo.HasRepeatingGroups = childGroupHasRepeatingGroups; currentIndex = particleData.currentIndex; if (currentIndex < currentGroupBase.Items.Count) { particle = (XmlSchemaParticle)currentGroupBase.Items[currentIndex++]; regEx.Append(currentGroupingInfo.ContentModelType == ContentModelType.Choice ? "|" : ", "); } else { // we were already at the end of the parent group, so just continue currentIndex++; //we are off the end of this list } } else { //No more particles to process break; } } } if (regEx.Length != 0) { typeInfo.ContentModelRegEx = regEx.ToString(); } }
internal static bool IsDerivedFromDatatype(XmlSchemaDatatype derivedDataType, XmlSchemaDatatype baseDataType, XmlSchemaDerivationMethod except) { if (DatatypeImplementation.AnySimpleType.Datatype == baseDataType) { return true; } return derivedDataType.IsDerivedFrom(baseDataType); }
public static bool IsDerivedFrom(XmlSchemaType derivedType, XmlSchemaType baseType, XmlSchemaDerivationMethod except) { }
string Write11_XmlSchemaDerivationMethod(XmlSchemaDerivationMethod v) { return(v.ToString()); }
public static bool IsDerivedFrom (XmlSchemaType derivedType, XmlSchemaType baseType, XmlSchemaDerivationMethod except) { if (derivedType.BaseXmlSchemaType == null) return false; if ((derivedType.DerivedBy & except) != 0) return false; if (derivedType.BaseXmlSchemaType == baseType) return true; return IsDerivedFrom (derivedType.BaseXmlSchemaType, baseType, except); }
private void TraverseParticle(XmlSchemaParticle particle, XmlSchemaComplexType baseType, ClrContentTypeInfo typeInfo, XmlSchemaDerivationMethod derivationMethod) { if (particleStack == null) { particleStack = new Stack<ParticleData>(); } else { particleStack.Clear(); } if (propertyNameTypeTable == null) { propertyNameTypeTable = new Dictionary<string, ClrPropertyInfo>(); } else { propertyNameTypeTable.Clear(); } XmlSchemaParticle baseParticle = baseType.ContentTypeParticle; ParticleData particleData; GroupingInfo parentGroupInfo = null; StringBuilder regEx = new StringBuilder(); XmlSchemaGroupBase currentGroupBase = null; GroupingInfo currentGroupingInfo = null; int currentIndex = 0; while (true) { // dont interrogate a particle if we are past the end of the list if (currentGroupBase == null || currentIndex <= currentGroupBase.Items.Count) { ParticleType particleType = particle.GetParticleType(); switch (particleType) { case ParticleType.Element: { XmlSchemaElement elem = particle as XmlSchemaElement; ClrPropertyInfo propertyInfo = null; bool fromBaseType = false; if (derivationMethod == XmlSchemaDerivationMethod.Extension && typeInfo.IsDerived) { if (baseParticle.ContainsElement(elem)) { fromBaseType = true; } else if (!typeInfo.InlineBaseType && baseType.ContainsName(elem.QualifiedName)) { typeInfo.InlineBaseType = true; } } propertyInfo = BuildProperty(elem, fromBaseType); regEx.Append(propertyInfo.PropertyName); AppendOccurenceToRegex(propertyInfo, regEx); //Add to parent if (currentGroupingInfo == null) { //Not adding property to propertyNameTypeTable as this case will occur only for pointless groups, so they have just one property BuildAnnotationInformation(propertyInfo, elem, false, false); typeInfo.AddMember(propertyInfo); } else { BuildAnnotationInformation(propertyInfo, elem, currentGroupingInfo.ContentModelType == ContentModelType.Choice, currentGroupingInfo.IsNested); currentGroupingInfo.AddChild(propertyInfo); SetPropertyFlags(propertyInfo, currentGroupingInfo, elem.ElementSchemaType); } break; } case ParticleType.Any: { regEx.Append("any"); XmlSchemaAny any = particle as XmlSchemaAny; if (derivationMethod == XmlSchemaDerivationMethod.Extension && typeInfo.IsDerived) { if (baseParticle.ContainsWildCard(any)) { typeInfo.HasElementWildCard = true;//ANY property in the base type will be reused } } //Note we always create a property info object to keep the original nesting structure in the schema //so it can be used to create a correct FSM; on the other hand, typeInfo.HasElementWildCard will indicate whether //we need to create a property in the resulting object type. ClrWildCardPropertyInfo wcPropertyInfo = BuildAnyProperty(any, !typeInfo.HasElementWildCard); //Add to parent if (currentGroupingInfo == null) { typeInfo.AddMember(wcPropertyInfo); } else { currentGroupingInfo.AddChild(wcPropertyInfo); } if (!typeInfo.HasElementWildCard) typeInfo.HasElementWildCard = true; break; } case ParticleType.Sequence: case ParticleType.Choice: case ParticleType.All: regEx.Append("("); if (currentGroupBase != null) { //already there is a group that we are processing, push it on stack to process sub-group particleStack.Push(new ParticleData(currentGroupBase, currentGroupingInfo, currentIndex)); currentIndex = 0; //Re-start index for new group base } parentGroupInfo = currentGroupingInfo; //Assign parent before creating child groupInfo currentGroupBase = particle as XmlSchemaGroupBase; Debug.Assert(currentGroupBase != null); currentGroupingInfo = new GroupingInfo((ContentModelType)((int)particleType), GetOccurence(currentGroupBase)); //Add to parent if (parentGroupInfo == null) { typeInfo.AddMember(currentGroupingInfo); parentGroupInfo = currentGroupingInfo; //Assign first time } else { parentGroupInfo.AddChild(currentGroupingInfo); parentGroupInfo.HasChildGroups = true; currentGroupingInfo.IsNested = true; if (parentGroupInfo.IsRepeating) { currentGroupingInfo.IsRepeating = true; } if (currentGroupingInfo.IsRepeating) { parentGroupInfo.HasRepeatingGroups = true; } } break; } } //Drill down into items if (currentGroupBase != null && currentIndex < currentGroupBase.Items.Count) { // if this isnt the first, then we need a seperator if (currentIndex > 0) { regEx.Append(currentGroupingInfo.ContentModelType == ContentModelType.Choice ? " | " : ", "); } particle = (XmlSchemaParticle)currentGroupBase.Items[currentIndex++]; } else { if (currentGroupBase != null) { regEx.Append(")"); AppendOccurenceToRegex(currentGroupingInfo, regEx); } if (particleStack.Count > 0) { bool childGroupHasRecurringElements = currentGroupingInfo.HasRecurrentElements; bool childGroupHasRepeatingGroups = currentGroupingInfo.HasRepeatingGroups; particleData = particleStack.Pop(); currentGroupBase = particleData.currentGroupBase; currentGroupingInfo = particleData.currentGroupingInfo; currentGroupingInfo.HasRecurrentElements = childGroupHasRecurringElements; currentGroupingInfo.HasRepeatingGroups = childGroupHasRepeatingGroups; currentIndex = particleData.currentIndex; if (currentIndex < currentGroupBase.Items.Count) { particle = (XmlSchemaParticle)currentGroupBase.Items[currentIndex++]; regEx.Append(currentGroupingInfo.ContentModelType == ContentModelType.Choice ? "|" : ", "); } else { // we were already at the end of the parent group, so just continue currentIndex++; //we are off the end of this list } } else { //No more particles to process break; } } } if (regEx.Length != 0) { typeInfo.ContentModelRegEx = regEx.ToString(); } }
public XmlSchemaType () { final = XmlSchemaDerivationMethod.None; QNameInternal = XmlQualifiedName.Empty; }
/// <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 static bool IsDerivedFromDatatype(object derivedType, object baseType, XmlSchemaDerivationMethod except) { if (XmlSchemaDatatype.AnyType == baseType) { return(true); } XmlSchemaDatatype dtDerived = derivedType as XmlSchemaDatatype; if (dtDerived == null) { return(false); } XmlSchemaDatatype dtBase = baseType as XmlSchemaDatatype; if (dtBase == null) { return(false); } return(dtDerived.IsDerivedFrom(dtBase)); }
internal static bool IsDerivedFrom(object derivedType, object baseType, XmlSchemaDerivationMethod except) { if (derivedType == baseType) { return true; } if (derivedType is XmlSchemaDatatype) { if ((except & XmlSchemaDerivationMethod.Restriction) != 0) { return false; } return IsDerivedFromDatatype(derivedType, baseType, except); } else if (derivedType is XmlSchemaType) { XmlSchemaType derivedSchemaType = (XmlSchemaType)derivedType; XmlSchemaType baseSchemaType = baseType as XmlSchemaType; if (baseSchemaType != null) { return IsDerivedFromBaseType(derivedSchemaType, baseSchemaType, except); } else { if ((except & derivedSchemaType.DerivedBy) != 0) { return false; } return IsDerivedFromDatatype(derivedSchemaType.Datatype, baseType, except); } } return false; }
internal void SetBlockResolved(XmlSchemaDerivationMethod value) { _blockResolved = value; }
private static bool IsDerivedFromDatatype(object derivedType, object baseType, XmlSchemaDerivationMethod except) { if (XmlSchemaDatatype.AnyType == baseType) { return true; } XmlSchemaDatatype dtDerived = derivedType as XmlSchemaDatatype; if (dtDerived == null) { return false; } XmlSchemaDatatype dtBase = baseType as XmlSchemaDatatype; if (dtBase == null) { return false; } return dtDerived.IsDerivedFrom(dtBase); }
// It is common to ElementLocallyValid::4 and SchemaValidityAssessment::1.2.1.2.4 private void AssessLocalTypeDerivationOK (object xsiType, object baseType, XmlSchemaDerivationMethod flag) { XmlSchemaType xsiSchemaType = xsiType as XmlSchemaType; ComplexType baseComplexType = baseType as ComplexType; ComplexType xsiComplexType = xsiSchemaType as ComplexType; if (xsiType != baseType) { // Extracted (not extraneous) check for 3.4.6 TypeDerivationOK. if (baseComplexType != null) flag |= baseComplexType.BlockResolved; if (flag == XmlSchemaDerivationMethod.All) { HandleError ("Prohibited element type substitution."); return; } else if (xsiSchemaType != null && (flag & xsiSchemaType.DerivedBy) != 0) { HandleError ("Prohibited element type substitution."); return; } } if (xsiComplexType != null) try { xsiComplexType.ValidateTypeDerivationOK (baseType, null, null); } catch (ValException ex) { // HandleError ("Locally specified schema complex type derivation failed. " + ex.Message, ex); HandleError (ex); } else { SimpleType xsiSimpleType = xsiType as SimpleType; if (xsiSimpleType != null) { try { xsiSimpleType.ValidateTypeDerivationOK (baseType, null, null, true); } catch (ValException ex) { // HandleError ("Locally specified schema simple type derivation failed. " + ex.Message, ex); HandleError (ex); } } else if (xsiType is XsDatatype) { // do nothing } else HandleError ("Primitive data type cannot be derived type using xsi:type specification."); } }
public static bool IsDerivedFrom(XmlSchemaType derivedType, XmlSchemaType baseType, XmlSchemaDerivationMethod except) { }
internal void SetFinalResolved(XmlSchemaDerivationMethod value) { finalResolved = value; }
internal void SetFinalResolved(XmlSchemaDerivationMethod value) { finalResolved = value; }
internal void SetDerivedBy(XmlSchemaDerivationMethod value) { derivedBy = value; }
public static bool IsDerivedFrom(XmlSchemaType derivedType, XmlSchemaType baseType, XmlSchemaDerivationMethod except) { if (derivedType == null || baseType == null) { return false; } if (derivedType == baseType) { return true; } if (baseType == XmlSchemaComplexType.AnyType) { //Not checking for restriction blocked since all types are implicitly derived by restriction from xs:anyType return true; } do { XmlSchemaSimpleType dt = derivedType as XmlSchemaSimpleType; XmlSchemaSimpleType bt = baseType as XmlSchemaSimpleType; if (bt != null && dt != null) { //SimpleTypes if (bt == DatatypeImplementation.AnySimpleType) { //Not checking block=restriction return true; } if ((except & derivedType.DerivedBy) != 0 || !dt.Datatype.IsDerivedFrom(bt.Datatype)) { return false; } return true; } else { //Complex types if ((except & derivedType.DerivedBy) != 0) { return false; } derivedType = derivedType.BaseXmlSchemaType; if (derivedType == baseType) { return true; } } } while(derivedType != null); return false; }
public static bool IsDerivedFrom(XmlSchemaType derivedType, XmlSchemaType baseType, XmlSchemaDerivationMethod except) { if (derivedType == null || baseType == null) { return(false); } if (derivedType == baseType) { return(true); } if (baseType == XmlSchemaComplexType.AnyType) //Not checking for restriction blocked since all types are implicitly derived by restriction from xs:anyType { return(true); } do { XmlSchemaSimpleType dt = derivedType as XmlSchemaSimpleType; XmlSchemaSimpleType bt = baseType as XmlSchemaSimpleType; if (bt != null && dt != null) //SimpleTypes { if (bt == DatatypeImplementation.AnySimpleType) //Not checking block=restriction { return(true); } if ((except & derivedType.DerivedBy) != 0 || !dt.Datatype.IsDerivedFrom(bt.Datatype)) { return(false); } return(true); } else //Complex types { if ((except & derivedType.DerivedBy) != 0) { return(false); } derivedType = derivedType.BaseXmlSchemaType; if (derivedType == baseType) { return(true); } } } while(derivedType != null); return(false); }
string Write11_XmlSchemaDerivationMethod(XmlSchemaDerivationMethod v) { return v.ToString(); }
internal static bool IsDerivedFromDatatype(XmlSchemaDatatype derivedDataType, XmlSchemaDatatype baseDataType, XmlSchemaDerivationMethod except) { if (DatatypeImplementation.AnySimpleType.Datatype == baseDataType) { return(true); } return(derivedDataType.IsDerivedFrom(baseDataType)); }
private void CompileLocalAttributes(XmlSchemaComplexType baseType, XmlSchemaComplexType derivedType, XmlSchemaObjectCollection attributes, XmlSchemaAnyAttribute anyAttribute, XmlSchemaDerivationMethod derivedBy) { XmlSchemaAnyAttribute baseAttributeWildcard = baseType != null ? baseType.AttributeWildcard : null; foreach (XmlSchemaObject obj in attributes) { if (obj is XmlSchemaAttribute) { XmlSchemaAttribute attribute = (XmlSchemaAttribute)obj; if (attribute.Use != XmlSchemaUse.Prohibited) { CompileAttribute(attribute); } if (derivedType.AttributeUses[attribute.QualifiedName] == null) { derivedType.AttributeUses.Add(attribute.QualifiedName, attribute); } else { SendValidationEvent(Res.Sch_DupAttributeUse, attribute.QualifiedName.ToString(), attribute); } } else { // is XmlSchemaAttributeGroupRef XmlSchemaAttributeGroupRef attributeGroupRef = (XmlSchemaAttributeGroupRef)obj; XmlSchemaAttributeGroup attributeGroup = (XmlSchemaAttributeGroup)this.schema.AttributeGroups[attributeGroupRef.RefName]; if (attributeGroup != null) { CompileAttributeGroup(attributeGroup); foreach (XmlSchemaAttribute attribute in attributeGroup.AttributeUses.Values) { if (derivedType.AttributeUses[attribute.QualifiedName] == null) { derivedType.AttributeUses.Add(attribute.QualifiedName, attribute); } else { SendValidationEvent(Res.Sch_DupAttributeUse, attribute.QualifiedName.ToString(), attributeGroupRef); } } anyAttribute = CompileAnyAttributeIntersection(anyAttribute, attributeGroup.AttributeWildcard); } else { SendValidationEvent(Res.Sch_UndefAttributeGroupRef, attributeGroupRef.RefName.ToString(), attributeGroupRef); } } } // check derivation rules if (baseType != null) { if (derivedBy == XmlSchemaDerivationMethod.Extension) { derivedType.SetAttributeWildcard(CompileAnyAttributeUnion(anyAttribute, baseAttributeWildcard)); foreach(XmlSchemaAttribute attributeBase in baseType.AttributeUses.Values) { XmlSchemaAttribute attribute = (XmlSchemaAttribute)derivedType.AttributeUses[attributeBase.QualifiedName]; if (attribute != null) { if (attribute.Use != XmlSchemaUse.Prohibited && attributeBase.Use != XmlSchemaUse.Prohibited) { if (attribute.AttributeType != attributeBase.AttributeType) { SendValidationEvent(Res.Sch_InvalidAttributeExtension, attribute); } } } else { derivedType.AttributeUses.Add(attributeBase.QualifiedName, attributeBase); } } } else { // derivedBy == XmlSchemaDerivationMethod.Restriction // Schema Component Constraint: Derivation Valid (Restriction, Complex) if ((anyAttribute != null) && (baseAttributeWildcard == null || !XmlSchemaAnyAttribute.IsSubset(anyAttribute, baseAttributeWildcard))) { SendValidationEvent(Res.Sch_InvalidAnyAttributeRestriction, derivedType); } else { derivedType.SetAttributeWildcard(anyAttribute); //complete wildcard } // Add form the base foreach(XmlSchemaAttribute attributeBase in baseType.AttributeUses.Values) { XmlSchemaAttribute attribute = (XmlSchemaAttribute)derivedType.AttributeUses[attributeBase.QualifiedName]; if (attribute == null) { derivedType.AttributeUses.Add(attributeBase.QualifiedName, attributeBase); } else { if (attributeBase.Use == XmlSchemaUse.Prohibited && attribute.Use != XmlSchemaUse.Prohibited) { #if DEBUG string position = string.Empty; if (derivedType.SourceUri != null) { position = " in " + derivedType.SourceUri + "(" + derivedType.LineNumber + ", " + derivedType.LinePosition + ")"; } Debug.WriteLineIf(CompModSwitches.XmlSchema.TraceError, "Invalid complexType attributes restriction" + position); Debug.WriteLineIf(CompModSwitches.XmlSchema.TraceError, " Base " + DumpAttributes(baseType.AttributeUses, baseType.AttributeWildcard)); Debug.WriteLineIf(CompModSwitches.XmlSchema.TraceError, " Derived " + DumpAttributes(derivedType.AttributeUses, derivedType.AttributeWildcard)); #endif SendValidationEvent(Res.Sch_AttributeRestrictionProhibited, attribute); } else if (attribute.Use == XmlSchemaUse.Prohibited) { continue; } else if (attributeBase.AttributeType == null || attribute.AttributeType == null || !XmlSchemaType.IsDerivedFrom(attribute.AttributeType, attributeBase.AttributeType, XmlSchemaDerivationMethod.Empty)) { SendValidationEvent(Res.Sch_AttributeRestrictionInvalid, attribute); } } } // Check additional ones are valid restriction of base's wildcard foreach(XmlSchemaAttribute attribute in derivedType.AttributeUses.Values) { XmlSchemaAttribute attributeBase = (XmlSchemaAttribute)baseType.AttributeUses[attribute.QualifiedName]; if (attributeBase != null) { continue; } if (baseAttributeWildcard == null || !baseAttributeWildcard.Allows(attribute.QualifiedName)) { #if DEBUG string position = string.Empty; if (derivedType.SourceUri != null) { position = " in " + derivedType.SourceUri + "(" + derivedType.LineNumber + ", " + derivedType.LinePosition + ")"; } Debug.WriteLineIf(CompModSwitches.XmlSchema.TraceError, "Invalid complexType attributes restriction" + position); Debug.WriteLineIf(CompModSwitches.XmlSchema.TraceError, " Base " + DumpAttributes(baseType.AttributeUses, baseType.AttributeWildcard)); Debug.WriteLineIf(CompModSwitches.XmlSchema.TraceError, " Derived " + DumpAttributes(derivedType.AttributeUses, derivedType.AttributeWildcard)); #endif SendValidationEvent(Res.Sch_AttributeRestrictionInvalidFromWildcard, attribute); } } } } else { derivedType.SetAttributeWildcard(anyAttribute); } }
internal void SetBlockResolved(XmlSchemaDerivationMethod value) { blockResolved = value; }
private void SetSchemaDefaults(XmlSchema schema) { if (schema.BlockDefault == XmlSchemaDerivationMethod.All) { this.blockDefault = XmlSchemaDerivationMethod.All; } else if (schema.BlockDefault == XmlSchemaDerivationMethod.None) { this.blockDefault = XmlSchemaDerivationMethod.Empty; } else { if ((schema.BlockDefault & ~(XmlSchemaDerivationMethod.Restriction | XmlSchemaDerivationMethod.Extension | XmlSchemaDerivationMethod.Substitution)) != XmlSchemaDerivationMethod.Empty) { base.SendValidationEvent("Sch_InvalidBlockDefaultValue", schema); } this.blockDefault = schema.BlockDefault & (XmlSchemaDerivationMethod.Restriction | XmlSchemaDerivationMethod.Extension | XmlSchemaDerivationMethod.Substitution); } if (schema.FinalDefault == XmlSchemaDerivationMethod.All) { this.finalDefault = XmlSchemaDerivationMethod.All; } else if (schema.FinalDefault == XmlSchemaDerivationMethod.None) { this.finalDefault = XmlSchemaDerivationMethod.Empty; } else { if ((schema.FinalDefault & ~(XmlSchemaDerivationMethod.Union | XmlSchemaDerivationMethod.List | XmlSchemaDerivationMethod.Restriction | XmlSchemaDerivationMethod.Extension)) != XmlSchemaDerivationMethod.Empty) { base.SendValidationEvent("Sch_InvalidFinalDefaultValue", schema); } this.finalDefault = schema.FinalDefault & (XmlSchemaDerivationMethod.Union | XmlSchemaDerivationMethod.List | XmlSchemaDerivationMethod.Restriction | XmlSchemaDerivationMethod.Extension); } this.elementFormDefault = schema.ElementFormDefault; if (this.elementFormDefault == XmlSchemaForm.None) { this.elementFormDefault = XmlSchemaForm.Unqualified; } this.attributeFormDefault = schema.AttributeFormDefault; if (this.attributeFormDefault == XmlSchemaForm.None) { this.attributeFormDefault = XmlSchemaForm.Unqualified; } }
// Is some value is read, return it. // If no values return empty. // If exception, return none public static XmlSchemaDerivationMethod ReadDerivationAttribute(XmlReader reader, out Exception innerExcpetion, string name, XmlSchemaDerivationMethod allowed) { innerExcpetion = null; try { string list = reader.Value; string warn = ""; XmlSchemaDerivationMethod val = 0; if(list.IndexOf("#all") != -1 && list.Trim() != "#all") { innerExcpetion = new Exception(list+" is not a valid value for "+ name +". #all if present must be the only value"); return XmlSchemaDerivationMethod.All; } foreach(string xsdm in XmlSchemaUtil.SplitList(list)) { switch(xsdm) { case "": val = AddFlag (val, XmlSchemaDerivationMethod.Empty, allowed); break; case "#all": val = AddFlag (val,XmlSchemaDerivationMethod.All, allowed); break; case "substitution": val = AddFlag (val,XmlSchemaDerivationMethod.Substitution, allowed); break; case "extension": val = AddFlag (val,XmlSchemaDerivationMethod.Extension, allowed); break; case "restriction": val = AddFlag (val,XmlSchemaDerivationMethod.Restriction, allowed); break; case "list": val = AddFlag (val,XmlSchemaDerivationMethod.List, allowed); break; case "union": val = AddFlag (val,XmlSchemaDerivationMethod.Union, allowed); break; default: warn += xsdm + " "; break; } } if(warn != "") innerExcpetion = new Exception(warn + "is/are not valid values for " + name); return val; } catch(Exception ex) { innerExcpetion = ex; return XmlSchemaDerivationMethod.None; } }