public override void FixtureInit() { XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection(); schemas.Add(SchemaCompletionData); XmlSchemaCompletionData xsdSchemaCompletionData = new XmlSchemaCompletionData(ResourceManager.GetXsdSchema()); schemas.Add(xsdSchemaCompletionData); XmlCompletionDataProvider provider = new XmlCompletionDataProvider(schemas, xsdSchemaCompletionData, String.Empty); string xml = GetSchema(); int index = xml.IndexOf("ref=\"coreattrs\""); index = xml.IndexOf("coreattrs", index); schemaAttributeGroup = (XmlSchemaAttributeGroup)XmlView.GetSchemaObjectSelected(xml, index, provider, SchemaCompletionData); }
public override void FixtureInit() { XmlSchemaCompletionCollection schemas = new XmlSchemaCompletionCollection(); schemas.Add(SchemaCompletion); XmlSchemaCompletion xsdSchemaCompletionData = new XmlSchemaCompletion(ResourceManager.ReadXsdSchema()); schemas.Add(xsdSchemaCompletionData); string xml = GetSchema(); int index = xml.IndexOf("ref=\"coreattrs\""); index = xml.IndexOf("coreattrs", index); XmlSchemaDefinition schemaDefinition = new XmlSchemaDefinition(schemas, SchemaCompletion); schemaAttributeGroup = (XmlSchemaAttributeGroup)schemaDefinition.GetSelectedSchemaObject(xml, index); }
internal override int Validate(ValidationEventHandler h, XmlSchema schema) { if (IsValidated(schema.CompilationId)) { return(errorCount); } if (redefined == null && redefinedObject != null) { redefinedObject.Compile(h, schema); redefined = (XmlSchemaAttributeGroup)redefinedObject; redefined.Validate(h, schema); } XmlSchemaObjectCollection actualAttributes = null; /* * if (this.redefined != null) { * actualAttributes = new XmlSchemaObjectCollection (); * foreach (XmlSchemaObject obj in Attributes) { * XmlSchemaAttributeGroupRef grp = obj as XmlSchemaAttributeGroupRef; * if (grp != null && grp.QualifiedName == this.QualifiedName) * actualAttributes.Add (redefined); * else * actualAttributes.Add (obj); * } * } * else */ actualAttributes = Attributes; attributeUses = new XmlSchemaObjectTable(); errorCount += XmlSchemaUtil.ValidateAttributesResolved(attributeUses, h, schema, actualAttributes, AnyAttribute, ref anyAttributeUse, redefined, false); ValidationId = schema.ValidationId; return(errorCount); }
private void RecursivelyCheckRedefinedAttributeGroups(XmlSchemaAttributeGroup attributeGroup, XmlSchemaAttributeGroup baseAttributeGroup) { if (baseAttributeGroup.Redefined != null) { RecursivelyCheckRedefinedAttributeGroups(baseAttributeGroup, baseAttributeGroup.Redefined); } if (attributeGroup.SelfReferenceCount == 0) { CompileAttributeGroup(baseAttributeGroup); CompileAttributeGroup(attributeGroup); CheckAtrributeGroupRestriction(baseAttributeGroup, attributeGroup); } }
private void CheckAtrributeGroupRestriction(XmlSchemaAttributeGroup baseAttributeGroup, XmlSchemaAttributeGroup derivedAttributeGroup) { XmlSchemaAnyAttribute baseAnyAtt = baseAttributeGroup.AttributeWildcard; XmlSchemaAnyAttribute derivedAnyAtt = derivedAttributeGroup.AttributeWildcard; if ((derivedAnyAtt != null) && (baseAnyAtt == null || !XmlSchemaAnyAttribute.IsSubset(derivedAnyAtt, baseAnyAtt) || !IsProcessContentsRestricted(null, derivedAnyAtt, baseAnyAtt))) { SendValidationEvent(Res.Sch_InvalidAnyAttributeRestriction, derivedAttributeGroup); } foreach(XmlSchemaAttribute attributeBase in baseAttributeGroup.AttributeUses.Values) { XmlSchemaAttribute attribute = (XmlSchemaAttribute)derivedAttributeGroup.AttributeUses[attributeBase.QualifiedName]; if (attribute != null) { if (attributeBase.Use == XmlSchemaUse.Prohibited && attribute.Use != XmlSchemaUse.Prohibited) { SendValidationEvent(Res.Sch_AttributeRestrictionProhibited, attribute); } else if (attributeBase.Use == XmlSchemaUse.Required && attribute.Use != XmlSchemaUse.Required) { SendValidationEvent(Res.Sch_AttributeUseInvalid, attribute); } else if (attribute.Use == XmlSchemaUse.Prohibited) { //If derived att is prohibited, continue 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); } } else if (attributeBase.Use == XmlSchemaUse.Required) { SendValidationEvent(Res.Sch_NoDerivedAttribute, attributeBase.QualifiedName.ToString(), baseAttributeGroup.QualifiedName.ToString(), derivedAttributeGroup); } } // Check additional ones are valid restriction of base's wildcard foreach(XmlSchemaAttribute attribute in derivedAttributeGroup.AttributeUses.Values) { XmlSchemaAttribute attributeBase = (XmlSchemaAttribute)baseAttributeGroup.AttributeUses[attribute.QualifiedName]; if (attributeBase != null) { continue; } if (baseAnyAtt == null || !baseAnyAtt.Allows(attribute.QualifiedName)) { SendValidationEvent(Res.Sch_AttributeRestrictionInvalidFromWildcard, attribute); } } }
private void CheckRefinedAttributeGroup(XmlSchemaAttributeGroup attributeGroup) { int count = 0; for (int i = 0; i < attributeGroup.Attributes.Count; ++i) { XmlSchemaAttributeGroupRef attrGroupRef = attributeGroup.Attributes[i] as XmlSchemaAttributeGroupRef; if (attrGroupRef != null && attrGroupRef.RefName == attributeGroup.QualifiedName) { count++; } } if (count > 1) { SendValidationEvent(Res.Sch_MultipleAttrGroupSelfRef, attributeGroup); } attributeGroup.SelfReferenceCount = count; }
private static void ReadContent(XmlSchema schema, XmlSchemaReader reader, ValidationEventHandler h) { reader.MoveToElement(); if (reader.LocalName != "schema" && reader.NamespaceURI != XmlSchema.Namespace && reader.NodeType != XmlNodeType.Element) { error(h, "UNREACHABLE CODE REACHED: Method: Schema.ReadContent, " + reader.LocalName + ", " + reader.NamespaceURI, null); } //(include | import | redefine | annotation)*, //((simpleType | complexType | group | attributeGroup | element | attribute | notation | annotation)* int level = 1; while (reader.ReadNextElement()) { if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName != xmlname) { error(h, "Should not happen :2: XmlSchema.Read, name=" + reader.Name, null); } break; } if (level <= 1) { if (reader.LocalName == "include") { XmlSchemaInclude include = XmlSchemaInclude.Read(reader, h); if (include != null) { schema.includes.Add(include); } continue; } if (reader.LocalName == "import") { XmlSchemaImport import = XmlSchemaImport.Read(reader, h); if (import != null) { schema.includes.Add(import); } continue; } if (reader.LocalName == "redefine") { XmlSchemaRedefine redefine = XmlSchemaRedefine.Read(reader, h); if (redefine != null) { schema.includes.Add(redefine); } continue; } if (reader.LocalName == "annotation") { XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h); if (annotation != null) { schema.items.Add(annotation); } continue; } } if (level <= 2) { level = 2; if (reader.LocalName == "simpleType") { XmlSchemaSimpleType stype = XmlSchemaSimpleType.Read(reader, h); if (stype != null) { schema.items.Add(stype); } continue; } if (reader.LocalName == "complexType") { XmlSchemaComplexType ctype = XmlSchemaComplexType.Read(reader, h); if (ctype != null) { schema.items.Add(ctype); } continue; } if (reader.LocalName == "group") { XmlSchemaGroup group = XmlSchemaGroup.Read(reader, h); if (group != null) { schema.items.Add(group); } continue; } if (reader.LocalName == "attributeGroup") { XmlSchemaAttributeGroup attributeGroup = XmlSchemaAttributeGroup.Read(reader, h); if (attributeGroup != null) { schema.items.Add(attributeGroup); } continue; } if (reader.LocalName == "element") { XmlSchemaElement element = XmlSchemaElement.Read(reader, h); if (element != null) { schema.items.Add(element); } continue; } if (reader.LocalName == "attribute") { XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader, h); if (attr != null) { schema.items.Add(attr); } continue; } if (reader.LocalName == "notation") { XmlSchemaNotation notation = XmlSchemaNotation.Read(reader, h); if (notation != null) { schema.items.Add(notation); } continue; } if (reader.LocalName == "annotation") { XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h); if (annotation != null) { schema.items.Add(annotation); } continue; } } reader.RaiseInvalidElementError(); } }
private void CompileAttributeGroup(XmlSchemaAttributeGroup attributeGroup) { if (attributeGroup.IsProcessing) { base.SendValidationEvent("Sch_AttributeGroupCircularRef", attributeGroup); } else if (attributeGroup.AttributeUses.Count <= 0) { attributeGroup.IsProcessing = true; XmlSchemaAnyAttribute anyAttribute = attributeGroup.AnyAttribute; for (int i = 0; i < attributeGroup.Attributes.Count; i++) { XmlSchemaAttribute xa = attributeGroup.Attributes[i] as XmlSchemaAttribute; if (xa != null) { if (xa.Use != XmlSchemaUse.Prohibited) { this.CompileAttribute(xa); } if (attributeGroup.AttributeUses[xa.QualifiedName] == null) { attributeGroup.AttributeUses.Add(xa.QualifiedName, xa); } else { base.SendValidationEvent("Sch_DupAttributeUse", xa.QualifiedName.ToString(), xa); } } else { XmlSchemaAttributeGroup redefined; XmlSchemaAttributeGroupRef source = (XmlSchemaAttributeGroupRef) attributeGroup.Attributes[i]; if ((attributeGroup.Redefined != null) && (source.RefName == attributeGroup.Redefined.QualifiedName)) { redefined = attributeGroup.Redefined; } else { redefined = (XmlSchemaAttributeGroup) this.schema.AttributeGroups[source.RefName]; } if (redefined != null) { this.CompileAttributeGroup(redefined); foreach (XmlSchemaAttribute attribute3 in redefined.AttributeUses.Values) { if (attributeGroup.AttributeUses[attribute3.QualifiedName] == null) { attributeGroup.AttributeUses.Add(attribute3.QualifiedName, attribute3); } else { base.SendValidationEvent("Sch_DupAttributeUse", attribute3.QualifiedName.ToString(), attribute3); } } anyAttribute = this.CompileAnyAttributeIntersection(anyAttribute, redefined.AttributeWildcard); } else { base.SendValidationEvent("Sch_UndefAttributeGroupRef", source.RefName.ToString(), source); } } } attributeGroup.AttributeWildcard = anyAttribute; attributeGroup.IsProcessing = false; } }
public virtual void Check (ConformanceCheckContext ctx, XmlSchemaAttributeGroup value) {}
//<redefine // id = ID // schemaLocation = anyURI // {any attributes with non-schema namespace . . .}> // Content: (annotation | (simpleType | complexType | group | attributeGroup))* //</redefine> internal static XmlSchemaRedefine Read(XmlSchemaReader reader, ValidationEventHandler h) { XmlSchemaRedefine redefine = new XmlSchemaRedefine(); reader.MoveToElement(); if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname) { error(h, "Should not happen :1: XmlSchemaRedefine.Read, name=" + reader.Name, null); reader.Skip(); return(null); } redefine.LineNumber = reader.LineNumber; redefine.LinePosition = reader.LinePosition; redefine.SourceUri = reader.BaseURI; while (reader.MoveToNextAttribute()) { if (reader.Name == "id") { redefine.Id = reader.Value; } else if (reader.Name == "schemaLocation") { redefine.SchemaLocation = reader.Value; } else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace) { error(h, reader.Name + " is not a valid attribute for redefine", null); } else { XmlSchemaUtil.ReadUnhandledAttribute(reader, redefine); } } reader.MoveToElement(); if (reader.IsEmptyElement) { return(redefine); } //(annotation | (simpleType | complexType | group | attributeGroup))* while (reader.ReadNextElement()) { if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName != xmlname) { error(h, "Should not happen :2: XmlSchemaRedefine.Read, name=" + reader.Name, null); } break; } if (reader.LocalName == "annotation") { XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h); if (annotation != null) { redefine.items.Add(annotation); } continue; } if (reader.LocalName == "simpleType") { XmlSchemaSimpleType simpleType = XmlSchemaSimpleType.Read(reader, h); if (simpleType != null) { redefine.items.Add(simpleType); } continue; } if (reader.LocalName == "complexType") { XmlSchemaComplexType complexType = XmlSchemaComplexType.Read(reader, h); if (complexType != null) { redefine.items.Add(complexType); } continue; } if (reader.LocalName == "group") { XmlSchemaGroup group = XmlSchemaGroup.Read(reader, h); if (group != null) { redefine.items.Add(group); } continue; } if (reader.LocalName == "attributeGroup") { XmlSchemaAttributeGroup attributeGroup = XmlSchemaAttributeGroup.Read(reader, h); if (attributeGroup != null) { redefine.items.Add(attributeGroup); } continue; } reader.RaiseInvalidElementError(); } return(redefine); }
protected override void Visit(XmlSchemaAttributeGroup group) { _attributeGroups.Add(group); }
private void ImportAttributeGroupMembers(XmlSchemaAttributeGroup group, string identifier, CodeIdentifiers members, CodeIdentifiers membersScope, string ns) { for (int i = 0; i < group.Attributes.Count; i++) { object obj2 = group.Attributes[i]; if (obj2 is XmlSchemaAttributeGroup) { this.ImportAttributeGroupMembers((XmlSchemaAttributeGroup) obj2, identifier, members, membersScope, ns); } else if (obj2 is XmlSchemaAttribute) { this.ImportAttributeMember((XmlSchemaAttribute) obj2, identifier, members, membersScope, ns); } } if (group.AnyAttribute != null) { this.ImportAnyAttributeMember(group.AnyAttribute, members, membersScope); } }
private void PreprocessAttributeGroup(XmlSchemaAttributeGroup attributeGroup) { if (attributeGroup.Name != null) { ValidateNameAttribute(attributeGroup); attributeGroup.QualifiedName = new XmlQualifiedName(attributeGroup.Name, this.targetNamespace); } else { SendValidationEvent(Res.Sch_MissRequiredAttribute, "name", attributeGroup); } PreprocessAttributes(attributeGroup.Attributes, attributeGroup.AnyAttribute); ValidateIdAttribute(attributeGroup); }
internal static XmlSchemaRedefine Read(XmlSchemaReader reader, ValidationEventHandler h) { XmlSchemaRedefine xmlSchemaRedefine = new XmlSchemaRedefine(); reader.MoveToElement(); if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "redefine") { XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaRedefine.Read, name=" + reader.Name, null); reader.Skip(); return(null); } xmlSchemaRedefine.LineNumber = reader.LineNumber; xmlSchemaRedefine.LinePosition = reader.LinePosition; xmlSchemaRedefine.SourceUri = reader.BaseURI; while (reader.MoveToNextAttribute()) { if (reader.Name == "id") { xmlSchemaRedefine.Id = reader.Value; } else if (reader.Name == "schemaLocation") { xmlSchemaRedefine.SchemaLocation = reader.Value; } else if ((reader.NamespaceURI == string.Empty && reader.Name != "xmlns") || reader.NamespaceURI == "http://www.w3.org/2001/XMLSchema") { XmlSchemaObject.error(h, reader.Name + " is not a valid attribute for redefine", null); } else { XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaRedefine); } } reader.MoveToElement(); if (reader.IsEmptyElement) { return(xmlSchemaRedefine); } while (reader.ReadNextElement()) { if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName != "redefine") { XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaRedefine.Read, name=" + reader.Name, null); } break; } if (reader.LocalName == "annotation") { XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h); if (xmlSchemaAnnotation != null) { xmlSchemaRedefine.items.Add(xmlSchemaAnnotation); } } else if (reader.LocalName == "simpleType") { XmlSchemaSimpleType xmlSchemaSimpleType = XmlSchemaSimpleType.Read(reader, h); if (xmlSchemaSimpleType != null) { xmlSchemaRedefine.items.Add(xmlSchemaSimpleType); } } else if (reader.LocalName == "complexType") { XmlSchemaComplexType xmlSchemaComplexType = XmlSchemaComplexType.Read(reader, h); if (xmlSchemaComplexType != null) { xmlSchemaRedefine.items.Add(xmlSchemaComplexType); } } else if (reader.LocalName == "group") { XmlSchemaGroup xmlSchemaGroup = XmlSchemaGroup.Read(reader, h); if (xmlSchemaGroup != null) { xmlSchemaRedefine.items.Add(xmlSchemaGroup); } } else if (reader.LocalName == "attributeGroup") { XmlSchemaAttributeGroup xmlSchemaAttributeGroup = XmlSchemaAttributeGroup.Read(reader, h); if (xmlSchemaAttributeGroup != null) { xmlSchemaRedefine.items.Add(xmlSchemaAttributeGroup); } } else { reader.RaiseInvalidElementError(); } } return(xmlSchemaRedefine); }
internal static XmlSchemaAttributeGroup Read(XmlSchemaReader reader, ValidationEventHandler h) { XmlSchemaAttributeGroup xmlSchemaAttributeGroup = new XmlSchemaAttributeGroup(); reader.MoveToElement(); if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "attributeGroup") { XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaAttributeGroup.Read, name=" + reader.Name, null); reader.SkipToEnd(); return(null); } xmlSchemaAttributeGroup.LineNumber = reader.LineNumber; xmlSchemaAttributeGroup.LinePosition = reader.LinePosition; xmlSchemaAttributeGroup.SourceUri = reader.BaseURI; while (reader.MoveToNextAttribute()) { if (reader.Name == "id") { xmlSchemaAttributeGroup.Id = reader.Value; } else if (reader.Name == "name") { xmlSchemaAttributeGroup.name = reader.Value; } else if ((reader.NamespaceURI == string.Empty && reader.Name != "xmlns") || reader.NamespaceURI == "http://www.w3.org/2001/XMLSchema") { XmlSchemaObject.error(h, reader.Name + " is not a valid attribute for attributeGroup in this context", null); } else { XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaAttributeGroup); } } reader.MoveToElement(); if (reader.IsEmptyElement) { return(xmlSchemaAttributeGroup); } int num = 1; while (reader.ReadNextElement()) { if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName != "attributeGroup") { XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaAttributeGroup.Read, name=" + reader.Name, null); } break; } if (num <= 1 && reader.LocalName == "annotation") { num = 2; XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h); if (xmlSchemaAnnotation != null) { xmlSchemaAttributeGroup.Annotation = xmlSchemaAnnotation; } } else { if (num <= 2) { if (reader.LocalName == "attribute") { num = 2; XmlSchemaAttribute xmlSchemaAttribute = XmlSchemaAttribute.Read(reader, h); if (xmlSchemaAttribute != null) { xmlSchemaAttributeGroup.Attributes.Add(xmlSchemaAttribute); } continue; } if (reader.LocalName == "attributeGroup") { num = 2; XmlSchemaAttributeGroupRef xmlSchemaAttributeGroupRef = XmlSchemaAttributeGroupRef.Read(reader, h); if (xmlSchemaAttributeGroupRef != null) { xmlSchemaAttributeGroup.attributes.Add(xmlSchemaAttributeGroupRef); } continue; } } if (num <= 3 && reader.LocalName == "anyAttribute") { num = 4; XmlSchemaAnyAttribute xmlSchemaAnyAttribute = XmlSchemaAnyAttribute.Read(reader, h); if (xmlSchemaAnyAttribute != null) { xmlSchemaAttributeGroup.AnyAttribute = xmlSchemaAnyAttribute; } } else { reader.RaiseInvalidElementError(); } } } return(xmlSchemaAttributeGroup); }
protected override void Visit(XmlSchemaAttributeGroup group) { PushTopic(TopicType.AttributeGroup, group.QualifiedName.Namespace, group, group.Name); base.Visit(group); PopTopic(); }
void Write31_XmlSchemaAttributeGroup(XmlSchemaAttributeGroup o) { if ((object)o == null) return; WriteStartElement("attributeGroup"); WriteAttribute(@"id", @"", ((System.String)o.@Id)); WriteAttribute(@"name", @"", ((System.String)o.@Name)); WriteAttributes((XmlAttribute[])o.@UnhandledAttributes, o); Write5_XmlSchemaAnnotation((XmlSchemaAnnotation)o.@Annotation); WriteSortedItems(o.Attributes); Write33_XmlSchemaAnyAttribute((XmlSchemaAnyAttribute)o.@AnyAttribute); WriteEndElement(); }
protected virtual void VisitXmlSchemaAttributeGroup(XmlSchemaAttributeGroup group) { foreach (XmlSchemaObject attribute in group.Attributes) { Dispatch(attribute); } }
private void PreprocessAttributeGroup(XmlSchemaAttributeGroup attributeGroup) { if (attributeGroup.Name != null) { this.ValidateNameAttribute(attributeGroup); attributeGroup.SetQualifiedName(new XmlQualifiedName(attributeGroup.Name, this.targetNamespace)); } else { base.SendValidationEvent("Sch_MissRequiredAttribute", "name", attributeGroup); } this.PreprocessAttributes(attributeGroup.Attributes, attributeGroup.AnyAttribute, attributeGroup); this.PreprocessAnnotation(attributeGroup); this.ValidateIdAttribute(attributeGroup); }
public virtual void VisitXmlSchemaAttribute(XmlSchemaAttributeGroup xmlSchemaAttributeGroup, XmlSchemaAttribute attribute) { }
public static int ValidateAttributesResolved( XmlSchemaObjectTable attributesResolved, ValidationEventHandler h, XmlSchema schema, XmlSchemaObjectCollection attributes, XmlSchemaAnyAttribute anyAttribute, ref XmlSchemaAnyAttribute anyAttributeUse, XmlSchemaAttributeGroup redefined, bool skipEquivalent) { int errorCount = 0; if (anyAttribute != null && anyAttributeUse == null) { anyAttributeUse = anyAttribute; } ArrayList newAttrNames = new ArrayList(); foreach (XmlSchemaObject xsobj in attributes) { XmlSchemaAttributeGroupRef grpRef = xsobj as XmlSchemaAttributeGroupRef; if (grpRef != null) { // Resolve attributeGroup redefinition. XmlSchemaAttributeGroup grp = null; if (redefined != null && grpRef.RefName == redefined.QualifiedName) { grp = redefined; } else { grp = schema.FindAttributeGroup(grpRef.RefName); } // otherwise, it might be missing sub components. if (grp == null) { if (!schema.missedSubComponents) // && schema.Schemas [grpRef.RefName.Namespace] != null) { grpRef.error(h, "Referenced attribute group " + grpRef.RefName + " was not found in the corresponding schema."); } continue; } if (grp.AttributeGroupRecursionCheck) { grp.error(h, "Attribute group recursion was found: " + grpRef.RefName); continue; } try { grp.AttributeGroupRecursionCheck = true; errorCount += grp.Validate(h, schema); } finally { grp.AttributeGroupRecursionCheck = false; } if (grp.AnyAttributeUse != null) { if (anyAttribute == null) { anyAttributeUse = grp.AnyAttributeUse; } } foreach (DictionaryEntry entry in grp.AttributeUses) { XmlSchemaAttribute attr = (XmlSchemaAttribute)entry.Value; if (StrictMsCompliant && attr.Use == XmlSchemaUse.Prohibited) { continue; } if (attr.RefName != null && attr.RefName != XmlQualifiedName.Empty && (!skipEquivalent || !AreAttributesEqual(attr, attributesResolved [attr.RefName] as XmlSchemaAttribute))) { AddToTable(attributesResolved, attr, attr.RefName, h); } else if (!skipEquivalent || !AreAttributesEqual(attr, attributesResolved [attr.QualifiedName] as XmlSchemaAttribute)) { AddToTable(attributesResolved, attr, attr.QualifiedName, h); } } } else { XmlSchemaAttribute attr = xsobj as XmlSchemaAttribute; if (attr != null) { errorCount += attr.Validate(h, schema); if (newAttrNames.Contains(attr.QualifiedName)) { attr.error(h, String.Format("Duplicate attributes was found for '{0}'", attr.QualifiedName)); } newAttrNames.Add(attr.QualifiedName); if (StrictMsCompliant && attr.Use == XmlSchemaUse.Prohibited) { continue; } if (attr.RefName != null && attr.RefName != XmlQualifiedName.Empty && (!skipEquivalent || !AreAttributesEqual(attr, attributesResolved [attr.RefName] as XmlSchemaAttribute))) { AddToTable(attributesResolved, attr, attr.RefName, h); } else if (!skipEquivalent || !AreAttributesEqual(attr, attributesResolved [attr.QualifiedName] as XmlSchemaAttribute)) { AddToTable(attributesResolved, attr, attr.QualifiedName, h); } } else { if (anyAttribute != null) { anyAttributeUse = (XmlSchemaAnyAttribute)xsobj; anyAttribute.Validate(h, schema); } } } } return(errorCount); }
public static int ValidateAttributesResolved ( XmlSchemaObjectTable attributesResolved, ValidationEventHandler h, XmlSchema schema, XmlSchemaObjectCollection attributes, XmlSchemaAnyAttribute anyAttribute, ref XmlSchemaAnyAttribute anyAttributeUse, XmlSchemaAttributeGroup redefined, bool skipEquivalent) { int errorCount = 0; if (anyAttribute != null && anyAttributeUse == null) anyAttributeUse = anyAttribute; ArrayList newAttrNames = new ArrayList (); foreach (XmlSchemaObject xsobj in attributes) { XmlSchemaAttributeGroupRef grpRef = xsobj as XmlSchemaAttributeGroupRef; if (grpRef != null) { // Resolve attributeGroup redefinition. XmlSchemaAttributeGroup grp = null; if (redefined != null && grpRef.RefName == redefined.QualifiedName) grp = redefined; else grp = schema.FindAttributeGroup (grpRef.RefName); // otherwise, it might be missing sub components. if (grp == null) { if (!schema.missedSubComponents)// && schema.Schemas [grpRef.RefName.Namespace] != null) grpRef.error (h, "Referenced attribute group " + grpRef.RefName + " was not found in the corresponding schema."); continue; } if (grp.AttributeGroupRecursionCheck) { grp.error (h, "Attribute group recursion was found: " + grpRef.RefName); continue; } try { grp.AttributeGroupRecursionCheck = true; errorCount += grp.Validate (h, schema); } finally { grp.AttributeGroupRecursionCheck = false; } if (grp.AnyAttributeUse != null) { if (anyAttribute == null) anyAttributeUse = grp.AnyAttributeUse; } foreach (DictionaryEntry entry in grp.AttributeUses) { XmlSchemaAttribute attr = (XmlSchemaAttribute) entry.Value; if (StrictMsCompliant && attr.Use == XmlSchemaUse.Prohibited) continue; if (attr.RefName != null && attr.RefName != XmlQualifiedName.Empty && (!skipEquivalent || !AreAttributesEqual (attr, attributesResolved [attr.RefName] as XmlSchemaAttribute))) AddToTable (attributesResolved, attr, attr.RefName, h); else if (!skipEquivalent || !AreAttributesEqual (attr, attributesResolved [attr.QualifiedName] as XmlSchemaAttribute)) AddToTable (attributesResolved, attr, attr.QualifiedName, h); } } else { XmlSchemaAttribute attr = xsobj as XmlSchemaAttribute; if (attr != null) { errorCount += attr.Validate (h, schema); if (newAttrNames.Contains (attr.QualifiedName)) attr.error (h, String.Format ("Duplicate attributes was found for '{0}'", attr.QualifiedName)); newAttrNames.Add (attr.QualifiedName); if (StrictMsCompliant && attr.Use == XmlSchemaUse.Prohibited) continue; if (attr.RefName != null && attr.RefName != XmlQualifiedName.Empty && (!skipEquivalent || !AreAttributesEqual (attr, attributesResolved [attr.RefName] as XmlSchemaAttribute))) AddToTable (attributesResolved, attr, attr.RefName, h); else if (!skipEquivalent || !AreAttributesEqual (attr, attributesResolved [attr.QualifiedName] as XmlSchemaAttribute)) AddToTable (attributesResolved, attr, attr.QualifiedName, h); } else { if (anyAttribute != null) { anyAttributeUse = (XmlSchemaAnyAttribute) xsobj; anyAttribute.Validate (h, schema); } } } } return errorCount; }
void DoCompile(ValidationEventHandler handler, List <CompiledSchemaMemo> handledUris, XmlSchemaSet col, XmlResolver resolver) { SetParent(); CompilationId = col.CompilationId; schemas = col; if (!schemas.Contains(this)) // e.g. xs:import { schemas.Add(this); } attributeGroups.Clear(); attributes.Clear(); elements.Clear(); groups.Clear(); notations.Clear(); schemaTypes.Clear(); named_identities.Clear(); ids.Clear(); compilationItems.Clear(); //1. Union and List are not allowed in block default if (BlockDefault != XmlSchemaDerivationMethod.All) { if ((BlockDefault & XmlSchemaDerivationMethod.List) != 0) { error(handler, "list is not allowed in blockDefault attribute"); } if ((BlockDefault & XmlSchemaDerivationMethod.Union) != 0) { error(handler, "union is not allowed in blockDefault attribute"); } } //2. Substitution is not allowed in finaldefault. if (FinalDefault != XmlSchemaDerivationMethod.All) { if ((FinalDefault & XmlSchemaDerivationMethod.Substitution) != 0) { error(handler, "substitution is not allowed in finalDefault attribute"); } } //3. id must be of type ID XmlSchemaUtil.CompileID(Id, this, IDCollection, handler); //4. targetNamespace should be of type anyURI or absent if (TargetNamespace != null) { if (TargetNamespace.Length == 0) { error(handler, "The targetNamespace attribute cannot have have empty string as its value."); } if (!XmlSchemaUtil.CheckAnyUri(TargetNamespace)) { error(handler, TargetNamespace + " is not a valid value for targetNamespace attribute of schema"); } } //5. version should be of type normalizedString if (!XmlSchemaUtil.CheckNormalizedString(Version)) { error(handler, Version + "is not a valid value for version attribute of schema"); } // Compile the content of this schema for (int i = 0; i < Items.Count; i++) { compilationItems.Add(Items [i]); } // First, we run into inclusion schemas to collect // compilation target items into compiledItems. for (int i = 0; i < Includes.Count; i++) { ProcessExternal(handler, handledUris, resolver, Includes [i] as XmlSchemaExternal, col); } // Compilation phase. // At least each Compile() must give unique (qualified) name for each component. // It also checks self-resolvable properties correctness. // Post compilation schema information contribution is not done here. // It should be done by Validate(). for (int i = 0; i < compilationItems.Count; i++) { XmlSchemaObject obj = compilationItems [i]; if (obj is XmlSchemaAnnotation) { int numerr = ((XmlSchemaAnnotation)obj).Compile(handler, this); errorCount += numerr; } else if (obj is XmlSchemaAttribute) { XmlSchemaAttribute attr = (XmlSchemaAttribute)obj; int numerr = attr.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable(Attributes, attr, attr.QualifiedName, handler); } } else if (obj is XmlSchemaAttributeGroup) { XmlSchemaAttributeGroup attrgrp = (XmlSchemaAttributeGroup)obj; int numerr = attrgrp.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( AttributeGroups, attrgrp, attrgrp.QualifiedName, handler); } } else if (obj is XmlSchemaComplexType) { XmlSchemaComplexType ctype = (XmlSchemaComplexType)obj; int numerr = ctype.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( schemaTypes, ctype, ctype.QualifiedName, handler); } } else if (obj is XmlSchemaSimpleType) { XmlSchemaSimpleType stype = (XmlSchemaSimpleType)obj; stype.islocal = false; //This simple type is toplevel int numerr = stype.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( SchemaTypes, stype, stype.QualifiedName, handler); } } else if (obj is XmlSchemaElement) { XmlSchemaElement elem = (XmlSchemaElement)obj; elem.parentIsSchema = true; int numerr = elem.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( Elements, elem, elem.QualifiedName, handler); } } else if (obj is XmlSchemaGroup) { XmlSchemaGroup grp = (XmlSchemaGroup)obj; int numerr = grp.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( Groups, grp, grp.QualifiedName, handler); } } else if (obj is XmlSchemaNotation) { XmlSchemaNotation ntn = (XmlSchemaNotation)obj; int numerr = ntn.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( Notations, ntn, ntn.QualifiedName, handler); } } else { ValidationHandler.RaiseValidationEvent( handler, null, String.Format("Object of Type {0} is not valid in Item Property of Schema", obj.GetType().Name), null, this, null, XmlSeverityType.Error); } } }
/// <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; }
internal static XmlSchema GetBuildInSchema() { if (builtInSchemaForXmlNS == null) { XmlSchema tempSchema = new XmlSchema(); tempSchema.TargetNamespace = XmlReservedNs.NsXml; tempSchema.Namespaces.Add("xml", XmlReservedNs.NsXml); XmlSchemaAttribute lang = new XmlSchemaAttribute(); lang.Name = "lang"; lang.SchemaTypeName = new XmlQualifiedName("language", XmlReservedNs.NsXs); tempSchema.Items.Add(lang); XmlSchemaAttribute xmlbase = new XmlSchemaAttribute(); xmlbase.Name = "base"; xmlbase.SchemaTypeName = new XmlQualifiedName("anyURI", XmlReservedNs.NsXs); tempSchema.Items.Add(xmlbase); XmlSchemaAttribute space = new XmlSchemaAttribute(); space.Name = "space"; XmlSchemaSimpleType type = new XmlSchemaSimpleType(); XmlSchemaSimpleTypeRestriction r = new XmlSchemaSimpleTypeRestriction(); r.BaseTypeName = new XmlQualifiedName("NCName", XmlReservedNs.NsXs); XmlSchemaEnumerationFacet space_default = new XmlSchemaEnumerationFacet(); space_default.Value = "default"; r.Facets.Add(space_default); XmlSchemaEnumerationFacet space_preserve = new XmlSchemaEnumerationFacet(); space_preserve.Value = "preserve"; r.Facets.Add(space_preserve); type.Content = r; space.SchemaType = type; space.DefaultValue = "preserve"; tempSchema.Items.Add(space); XmlSchemaAttributeGroup attributeGroup = new XmlSchemaAttributeGroup(); attributeGroup.Name = "specialAttrs"; XmlSchemaAttribute langRef = new XmlSchemaAttribute(); langRef.RefName = new XmlQualifiedName("lang", XmlReservedNs.NsXml); attributeGroup.Attributes.Add(langRef); XmlSchemaAttribute spaceRef = new XmlSchemaAttribute(); spaceRef.RefName = new XmlQualifiedName("space", XmlReservedNs.NsXml); attributeGroup.Attributes.Add(spaceRef); XmlSchemaAttribute baseRef = new XmlSchemaAttribute(); baseRef.RefName = new XmlQualifiedName("base", XmlReservedNs.NsXml); attributeGroup.Attributes.Add(baseRef); tempSchema.Items.Add(attributeGroup); tempSchema.IsPreprocessed = true; tempSchema.CompileSchemaInSet(new NameTable(), null, null); //compile built-in schema Interlocked.CompareExchange<XmlSchema>(ref builtInSchemaForXmlNS, tempSchema, null); } return builtInSchemaForXmlNS; }
internal override int Validate(ValidationEventHandler h, XmlSchema schema) { if (IsValidated (schema.CompilationId)) return errorCount; if (redefined == null && redefinedObject != null) { redefinedObject.Compile (h, schema); redefined = (XmlSchemaAttributeGroup) redefinedObject; redefined.Validate (h, schema); } XmlSchemaObjectCollection actualAttributes = null; /* if (this.redefined != null) { actualAttributes = new XmlSchemaObjectCollection (); foreach (XmlSchemaObject obj in Attributes) { XmlSchemaAttributeGroupRef grp = obj as XmlSchemaAttributeGroupRef; if (grp != null && grp.QualifiedName == this.QualifiedName) actualAttributes.Add (redefined); else actualAttributes.Add (obj); } } else */ actualAttributes = Attributes; attributeUses = new XmlSchemaObjectTable (); errorCount += XmlSchemaUtil.ValidateAttributesResolved (attributeUses, h, schema, actualAttributes, AnyAttribute, ref anyAttributeUse, redefined, false); ValidationId = schema.ValidationId; return errorCount; }
private void CompileAttributeGroup(XmlSchemaAttributeGroup attributeGroup) { if (attributeGroup.IsProcessing) { SendValidationEvent(Res.Sch_AttributeGroupCircularRef, attributeGroup); return; } if (attributeGroup.AttributeUses.Count > 0) {// already checked return; } attributeGroup.IsProcessing = true; XmlSchemaAnyAttribute anyAttribute = attributeGroup.AnyAttribute; try { for (int i = 0; i < attributeGroup.Attributes.Count; ++i) { XmlSchemaAttribute attr = attributeGroup.Attributes[i] as XmlSchemaAttribute; if (attr != null) { if (attr.Use == XmlSchemaUse.Prohibited) { continue; } CompileAttribute(attr); if (attributeGroup.AttributeUses[attr.QualifiedName] == null) { attributeGroup.AttributeUses.Add(attr.QualifiedName, attr); } else { SendValidationEvent(Res.Sch_DupAttributeUse, attr.QualifiedName.ToString(), attr); } } else { // XmlSchemaAttributeGroupRef XmlSchemaAttributeGroupRef attributeGroupRef = (XmlSchemaAttributeGroupRef)attributeGroup.Attributes[i]; XmlSchemaAttributeGroup attributeGroupResolved; if (attributeGroup.Redefined != null && attributeGroupRef.RefName == attributeGroup.Redefined.QualifiedName) { attributeGroupResolved = (XmlSchemaAttributeGroup)attributeGroup.Redefined; } else { attributeGroupResolved = (XmlSchemaAttributeGroup)attributeGroups[attributeGroupRef.RefName]; } if (attributeGroupResolved != null) { CompileAttributeGroup(attributeGroupResolved); foreach (XmlSchemaAttribute attribute in attributeGroupResolved.AttributeUses.Values) { if (attributeGroup.AttributeUses[attribute.QualifiedName] == null) { attributeGroup.AttributeUses.Add(attribute.QualifiedName, attribute); } else { SendValidationEvent(Res.Sch_DupAttributeUse, attribute.QualifiedName.ToString(), attribute); } } anyAttribute = CompileAnyAttributeIntersection(anyAttribute, attributeGroupResolved.AttributeWildcard); } else { SendValidationEvent(Res.Sch_UndefAttributeGroupRef, attributeGroupRef.RefName.ToString(), attributeGroupRef); } } } attributeGroup.AttributeWildcard = anyAttribute; } finally { attributeGroup.IsProcessing = false; } }
//<attributeGroup // id = ID // name = NCName // ref = QName // Not present in this class. // {any attributes with non-schema namespace . . .}> // Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?)) //</attributeGroup> internal static XmlSchemaAttributeGroup Read(XmlSchemaReader reader, ValidationEventHandler h) { XmlSchemaAttributeGroup attrgrp = new XmlSchemaAttributeGroup(); reader.MoveToElement(); if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname) { error(h,"Should not happen :1: XmlSchemaAttributeGroup.Read, name="+reader.Name,null); reader.SkipToEnd(); return null; } attrgrp.LineNumber = reader.LineNumber; attrgrp.LinePosition = reader.LinePosition; attrgrp.SourceUri = reader.BaseURI; while(reader.MoveToNextAttribute()) { if(reader.Name == "id") { attrgrp.Id = reader.Value; } else if(reader.Name == "name") { attrgrp.name = reader.Value; } else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace) { error(h,reader.Name + " is not a valid attribute for attributeGroup in this context",null); } else { XmlSchemaUtil.ReadUnhandledAttribute(reader,attrgrp); } } reader.MoveToElement(); if(reader.IsEmptyElement) return attrgrp; //Content: 1.annotation?, 2.(attribute | attributeGroup)*, 3.anyAttribute? int level = 1; while(reader.ReadNextElement()) { if(reader.NodeType == XmlNodeType.EndElement) { if(reader.LocalName != xmlname) error(h,"Should not happen :2: XmlSchemaAttributeGroup.Read, name="+reader.Name,null); break; } if(level <= 1 && reader.LocalName == "annotation") { level = 2; //Only one annotation XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h); if(annotation != null) attrgrp.Annotation = annotation; continue; } if(level <= 2) { if(reader.LocalName == "attribute") { level = 2; XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader,h); if(attr != null) attrgrp.Attributes.Add(attr); continue; } if(reader.LocalName == "attributeGroup") { level = 2; XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader,h); if(attr != null) attrgrp.attributes.Add(attr); continue; } } if(level <= 3 && reader.LocalName == "anyAttribute") { level = 4; XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader,h); if(anyattr != null) attrgrp.AnyAttribute = anyattr; continue; } reader.RaiseInvalidElementError(); } return attrgrp; }
private void CleanupAttributeGroup(XmlSchemaAttributeGroup attributeGroup) { CleanupAttributes(attributeGroup.Attributes); attributeGroup.AttributeUses.Clear(); attributeGroup.AttributeWildcard = null; if (attributeGroup.Redefined != null) { CleanupAttributeGroup(attributeGroup.Redefined); } }
private void CheckAtrributeGroupRestriction(XmlSchemaAttributeGroup baseAttributeGroup, XmlSchemaAttributeGroup derivedAttributeGroup) { XmlSchemaAnyAttribute attributeWildcard = baseAttributeGroup.AttributeWildcard; XmlSchemaAnyAttribute sub = derivedAttributeGroup.AttributeWildcard; if ((sub != null) && (((attributeWildcard == null) || !XmlSchemaAnyAttribute.IsSubset(sub, attributeWildcard)) || !this.IsProcessContentsRestricted(null, sub, attributeWildcard))) { base.SendValidationEvent("Sch_InvalidAnyAttributeRestriction", derivedAttributeGroup); } foreach (XmlSchemaAttribute attribute3 in baseAttributeGroup.AttributeUses.Values) { XmlSchemaAttribute source = (XmlSchemaAttribute) derivedAttributeGroup.AttributeUses[attribute3.QualifiedName]; if (source != null) { if ((attribute3.Use == XmlSchemaUse.Prohibited) && (source.Use != XmlSchemaUse.Prohibited)) { base.SendValidationEvent("Sch_AttributeRestrictionProhibited", source); } else if ((attribute3.Use == XmlSchemaUse.Required) && (source.Use != XmlSchemaUse.Required)) { base.SendValidationEvent("Sch_AttributeUseInvalid", source); } else if (source.Use != XmlSchemaUse.Prohibited) { if (((attribute3.AttributeSchemaType == null) || (source.AttributeSchemaType == null)) || !XmlSchemaType.IsDerivedFrom(source.AttributeSchemaType, attribute3.AttributeSchemaType, XmlSchemaDerivationMethod.Empty)) { base.SendValidationEvent("Sch_AttributeRestrictionInvalid", source); } else if (!this.IsFixedEqual(attribute3.AttDef, source.AttDef)) { base.SendValidationEvent("Sch_AttributeFixedInvalid", source); } } } else if (attribute3.Use == XmlSchemaUse.Required) { base.SendValidationEvent("Sch_NoDerivedAttribute", attribute3.QualifiedName.ToString(), baseAttributeGroup.QualifiedName.ToString(), derivedAttributeGroup); } } foreach (XmlSchemaAttribute attribute5 in derivedAttributeGroup.AttributeUses.Values) { if ((((XmlSchemaAttribute) baseAttributeGroup.AttributeUses[attribute5.QualifiedName]) == null) && ((attributeWildcard == null) || !attributeWildcard.Allows(attribute5.QualifiedName))) { base.SendValidationEvent("Sch_AttributeRestrictionInvalidFromWildcard", attribute5); } } }
private void SetContainer(State state, object container) { switch (state) { case State.Root: break; case State.Schema: break; case State.Annotation: this.annotation = (XmlSchemaAnnotation)container; break; case State.Include: this.include = (XmlSchemaInclude)container; break; case State.Import: this.import = (XmlSchemaImport)container; break; case State.Element: this.element = (XmlSchemaElement)container; break; case State.Attribute: this.attribute = (XmlSchemaAttribute)container; break; case State.AttributeGroup: this.attributeGroup = (XmlSchemaAttributeGroup)container; break; case State.AttributeGroupRef: this.attributeGroupRef = (XmlSchemaAttributeGroupRef)container; break; case State.AnyAttribute: this.anyAttribute = (XmlSchemaAnyAttribute)container; break; case State.Group: this.group = (XmlSchemaGroup)container; break; case State.GroupRef: this.groupRef = (XmlSchemaGroupRef)container; break; case State.All: this.all = (XmlSchemaAll)container; break; case State.Choice: this.choice = (XmlSchemaChoice)container; break; case State.Sequence: this.sequence = (XmlSchemaSequence)container; break; case State.Any: this.anyElement = (XmlSchemaAny)container; break; case State.Notation: this.notation = (XmlSchemaNotation)container; break; case State.SimpleType: this.simpleType = (XmlSchemaSimpleType)container; break; case State.ComplexType: this.complexType = (XmlSchemaComplexType)container; break; case State.ComplexContent: this.complexContent = (XmlSchemaComplexContent)container; break; case State.ComplexContentExtension: this.complexContentExtension = (XmlSchemaComplexContentExtension)container; break; case State.ComplexContentRestriction: this.complexContentRestriction = (XmlSchemaComplexContentRestriction)container; break; case State.SimpleContent: this.simpleContent = (XmlSchemaSimpleContent)container; break; case State.SimpleContentExtension: this.simpleContentExtension = (XmlSchemaSimpleContentExtension)container; break; case State.SimpleContentRestriction: this.simpleContentRestriction = (XmlSchemaSimpleContentRestriction)container; break; case State.SimpleTypeUnion: this.simpleTypeUnion = (XmlSchemaSimpleTypeUnion)container; break; case State.SimpleTypeList: this.simpleTypeList = (XmlSchemaSimpleTypeList)container; break; case State.SimpleTypeRestriction: this.simpleTypeRestriction = (XmlSchemaSimpleTypeRestriction)container; break; case State.Unique: case State.Key: case State.KeyRef: this.identityConstraint = (XmlSchemaIdentityConstraint)container; break; case State.Selector: case State.Field: this.xpath = (XmlSchemaXPath)container; break; case State.MinExclusive: case State.MinInclusive: case State.MaxExclusive: case State.MaxInclusive: case State.TotalDigits: case State.FractionDigits: case State.Length: case State.MinLength: case State.MaxLength: case State.Enumeration: case State.Pattern: case State.WhiteSpace: this.facet = (XmlSchemaFacet)container; break; case State.AppInfo: this.appInfo = (XmlSchemaAppInfo)container; break; case State.Documentation: this.documentation = (XmlSchemaDocumentation)container; break; case State.Redefine: this.redefine = (XmlSchemaRedefine)container; break; default: Debug.Assert(false, "State is " + state); break; } }
void DoCompile(ValidationEventHandler handler, Hashtable handledUris, XmlSchemaSet col, XmlResolver resolver) { SetParent(); CompilationId = col.CompilationId; schemas = col; if (!schemas.Contains(this)) // e.g. xs:import { schemas.Add(this); } attributeGroups.Clear(); attributes.Clear(); elements.Clear(); groups.Clear(); notations.Clear(); schemaTypes.Clear(); //1. Union and List are not allowed in block default if (BlockDefault != XmlSchemaDerivationMethod.All) { if ((BlockDefault & XmlSchemaDerivationMethod.List) != 0) { error(handler, "list is not allowed in blockDefault attribute"); } if ((BlockDefault & XmlSchemaDerivationMethod.Union) != 0) { error(handler, "union is not allowed in blockDefault attribute"); } } //2. Substitution is not allowed in finaldefault. if (FinalDefault != XmlSchemaDerivationMethod.All) { if ((FinalDefault & XmlSchemaDerivationMethod.Substitution) != 0) { error(handler, "substitution is not allowed in finalDefault attribute"); } } //3. id must be of type ID XmlSchemaUtil.CompileID(Id, this, col.IDCollection, handler); //4. targetNamespace should be of type anyURI or absent if (TargetNamespace != null) { if (TargetNamespace.Length == 0) { error(handler, "The targetNamespace attribute cannot have have empty string as its value."); } if (!XmlSchemaUtil.CheckAnyUri(TargetNamespace)) { error(handler, TargetNamespace + " is not a valid value for targetNamespace attribute of schema"); } } //5. version should be of type normalizedString if (!XmlSchemaUtil.CheckNormalizedString(Version)) { error(handler, Version + "is not a valid value for version attribute of schema"); } // Compile the content of this schema compilationItems = new XmlSchemaObjectCollection(); for (int i = 0; i < Items.Count; i++) { compilationItems.Add(Items [i]); } // First, we run into inclusion schemas to collect // compilation target items into compiledItems. for (int i = 0; i < Includes.Count; i++) { XmlSchemaExternal ext = Includes [i] as XmlSchemaExternal; if (ext == null) { error(handler, String.Format("Object of Type {0} is not valid in Includes Property of XmlSchema", Includes [i].GetType().Name)); continue; } if (ext.SchemaLocation == null) { continue; } Stream stream = null; string url = null; if (resolver != null) { url = GetResolvedUri(resolver, ext.SchemaLocation); if (handledUris.Contains(url)) { // This schema is already handled, so simply skip (otherwise, duplicate definition errrors occur. continue; } handledUris.Add(url, url); try { stream = resolver.GetEntity(new Uri(url), null, typeof(Stream)) as Stream; } catch (Exception) { // LAMESPEC: This is not good way to handle errors, but since we cannot know what kind of XmlResolver will come, so there are no mean to avoid this ugly catch. warn(handler, "Could not resolve schema location URI: " + url); stream = null; } } // Process redefinition children in advance. XmlSchemaRedefine redefine = Includes [i] as XmlSchemaRedefine; if (redefine != null) { for (int j = 0; j < redefine.Items.Count; j++) { XmlSchemaObject redefinedObj = redefine.Items [j]; redefinedObj.isRedefinedComponent = true; redefinedObj.isRedefineChild = true; if (redefinedObj is XmlSchemaType || redefinedObj is XmlSchemaGroup || redefinedObj is XmlSchemaAttributeGroup) { compilationItems.Add(redefinedObj); } else { error(handler, "Redefinition is only allowed to simpleType, complexType, group and attributeGroup."); } } } XmlSchema includedSchema = null; if (stream == null) { // It is missing schema components. missedSubComponents = true; continue; } else { XmlTextReader xtr = null; try { xtr = new XmlTextReader(url, stream, nameTable); includedSchema = XmlSchema.Read(xtr, handler); } finally { if (xtr != null) { xtr.Close(); } } includedSchema.schemas = schemas; } includedSchema.SetParent(); ext.Schema = includedSchema; // Set - actual - target namespace for the included schema * before compilation*. XmlSchemaImport import = ext as XmlSchemaImport; if (import != null) { if (TargetNamespace == includedSchema.TargetNamespace) { error(handler, "Target namespace must be different from that of included schema."); continue; } else if (includedSchema.TargetNamespace != import.Namespace) { error(handler, "Attribute namespace and its importing schema's target namespace must be the same."); continue; } } else { if (TargetNamespace == null && includedSchema.TargetNamespace != null) { error(handler, "Target namespace is required to include a schema which has its own target namespace"); continue; } else if (TargetNamespace != null && includedSchema.TargetNamespace == null) { includedSchema.TargetNamespace = TargetNamespace; } } // Do not compile included schema here. AddExternalComponentsTo(includedSchema, compilationItems); } // Compilation phase. // At least each Compile() must give unique (qualified) name for each component. // It also checks self-resolvable properties correctness. // Post compilation schema information contribution is not done here. // It should be done by Validate(). for (int i = 0; i < compilationItems.Count; i++) { XmlSchemaObject obj = compilationItems [i]; if (obj is XmlSchemaAnnotation) { int numerr = ((XmlSchemaAnnotation)obj).Compile(handler, this); errorCount += numerr; } else if (obj is XmlSchemaAttribute) { XmlSchemaAttribute attr = (XmlSchemaAttribute)obj; int numerr = attr.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable(Attributes, attr, attr.QualifiedName, handler); } } else if (obj is XmlSchemaAttributeGroup) { XmlSchemaAttributeGroup attrgrp = (XmlSchemaAttributeGroup)obj; int numerr = attrgrp.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( AttributeGroups, attrgrp, attrgrp.QualifiedName, handler); } } else if (obj is XmlSchemaComplexType) { XmlSchemaComplexType ctype = (XmlSchemaComplexType)obj; int numerr = ctype.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( schemaTypes, ctype, ctype.QualifiedName, handler); } } else if (obj is XmlSchemaSimpleType) { XmlSchemaSimpleType stype = (XmlSchemaSimpleType)obj; stype.islocal = false; //This simple type is toplevel int numerr = stype.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( SchemaTypes, stype, stype.QualifiedName, handler); } } else if (obj is XmlSchemaElement) { XmlSchemaElement elem = (XmlSchemaElement)obj; elem.parentIsSchema = true; int numerr = elem.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( Elements, elem, elem.QualifiedName, handler); } } else if (obj is XmlSchemaGroup) { XmlSchemaGroup grp = (XmlSchemaGroup)obj; int numerr = grp.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( Groups, grp, grp.QualifiedName, handler); } } else if (obj is XmlSchemaNotation) { XmlSchemaNotation ntn = (XmlSchemaNotation)obj; int numerr = ntn.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( Notations, ntn, ntn.QualifiedName, handler); } } else { ValidationHandler.RaiseValidationEvent( handler, null, String.Format("Object of Type {0} is not valid in Item Property of Schema", obj.GetType().Name), null, this, null, XmlSeverityType.Error); } } }
//<attributeGroup // id = ID // name = NCName // ref = QName // Not present in this class. // {any attributes with non-schema namespace . . .}> // Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?)) //</attributeGroup> internal static XmlSchemaAttributeGroup Read(XmlSchemaReader reader, ValidationEventHandler h) { XmlSchemaAttributeGroup attrgrp = new XmlSchemaAttributeGroup(); reader.MoveToElement(); if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname) { error(h, "Should not happen :1: XmlSchemaAttributeGroup.Read, name=" + reader.Name, null); reader.SkipToEnd(); return(null); } attrgrp.LineNumber = reader.LineNumber; attrgrp.LinePosition = reader.LinePosition; attrgrp.SourceUri = reader.BaseURI; while (reader.MoveToNextAttribute()) { if (reader.Name == "id") { attrgrp.Id = reader.Value; } else if (reader.Name == "name") { attrgrp.name = reader.Value; } else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace) { error(h, reader.Name + " is not a valid attribute for attributeGroup in this context", null); } else { XmlSchemaUtil.ReadUnhandledAttribute(reader, attrgrp); } } reader.MoveToElement(); if (reader.IsEmptyElement) { return(attrgrp); } //Content: 1.annotation?, 2.(attribute | attributeGroup)*, 3.anyAttribute? int level = 1; while (reader.ReadNextElement()) { if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName != xmlname) { error(h, "Should not happen :2: XmlSchemaAttributeGroup.Read, name=" + reader.Name, null); } break; } if (level <= 1 && reader.LocalName == "annotation") { level = 2; //Only one annotation XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h); if (annotation != null) { attrgrp.Annotation = annotation; } continue; } if (level <= 2) { if (reader.LocalName == "attribute") { level = 2; XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader, h); if (attr != null) { attrgrp.Attributes.Add(attr); } continue; } if (reader.LocalName == "attributeGroup") { level = 2; XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader, h); if (attr != null) { attrgrp.attributes.Add(attr); } continue; } } if (level <= 3 && reader.LocalName == "anyAttribute") { level = 4; XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader, h); if (anyattr != null) { attrgrp.AnyAttribute = anyattr; } continue; } reader.RaiseInvalidElementError(); } return(attrgrp); }
private void HandleAttributeGroup(XmlSchemaAttributeGroup attributeGroup, DataTable table, bool isBase) { foreach (XmlSchemaObject obj in attributeGroup.Attributes) { if (obj is XmlSchemaAttribute) { HandleAttributeColumn((XmlSchemaAttribute) obj, table, isBase); } else { // XmlSchemaAttributeGroupRef XmlSchemaAttributeGroupRef attributeGroupRef = (XmlSchemaAttributeGroupRef)obj; XmlSchemaAttributeGroup attributeGroupResolved; if (attributeGroup.RedefinedAttributeGroup != null && attributeGroupRef.RefName == new XmlQualifiedName(attributeGroup.Name, attributeGroupRef.RefName.Namespace)) { attributeGroupResolved = (XmlSchemaAttributeGroup)attributeGroup.RedefinedAttributeGroup; } else { attributeGroupResolved = (XmlSchemaAttributeGroup)attributeGroups[attributeGroupRef.RefName]; } if (attributeGroupResolved != null) { HandleAttributeGroup(attributeGroupResolved, table, isBase); } } } }
private static void CleanupAttributeGroup(XmlSchemaAttributeGroup attributeGroup) { CleanupAttributes(attributeGroup.Attributes); attributeGroup.AttributeUses.Clear(); attributeGroup.AttributeWildcard = null; }
private void CheckRefinedAttributeGroup(XmlSchemaAttributeGroup attributeGroup) { int count = 0; foreach (object obj in attributeGroup.Attributes) { if (obj is XmlSchemaAttributeGroupRef && ((XmlSchemaAttributeGroupRef)obj).RefName == attributeGroup.QualifiedName) { count++; } } if (count > 1) { SendValidationEvent(Res.Sch_MultipleAttrGroupSelfRef, attributeGroup); } attributeGroup.SelfReferenceCount = count; }
internal static XmlSchema GetBuildInSchema() { if (builtInSchemaForXmlNS == null) { XmlSchema schema = new XmlSchema { TargetNamespace = "http://www.w3.org/XML/1998/namespace" }; schema.Namespaces.Add("xml", "http://www.w3.org/XML/1998/namespace"); XmlSchemaAttribute item = new XmlSchemaAttribute { Name = "lang", SchemaTypeName = new XmlQualifiedName("language", "http://www.w3.org/2001/XMLSchema") }; schema.Items.Add(item); XmlSchemaAttribute attribute2 = new XmlSchemaAttribute { Name = "base", SchemaTypeName = new XmlQualifiedName("anyURI", "http://www.w3.org/2001/XMLSchema") }; schema.Items.Add(attribute2); XmlSchemaAttribute attribute3 = new XmlSchemaAttribute { Name = "space" }; XmlSchemaSimpleType type = new XmlSchemaSimpleType(); XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction { BaseTypeName = new XmlQualifiedName("NCName", "http://www.w3.org/2001/XMLSchema") }; XmlSchemaEnumerationFacet facet = new XmlSchemaEnumerationFacet { Value = "default" }; restriction.Facets.Add(facet); XmlSchemaEnumerationFacet facet2 = new XmlSchemaEnumerationFacet { Value = "preserve" }; restriction.Facets.Add(facet2); type.Content = restriction; attribute3.SchemaType = type; attribute3.DefaultValue = "preserve"; schema.Items.Add(attribute3); XmlSchemaAttributeGroup group = new XmlSchemaAttributeGroup { Name = "specialAttrs" }; XmlSchemaAttribute attribute4 = new XmlSchemaAttribute { RefName = new XmlQualifiedName("lang", "http://www.w3.org/XML/1998/namespace") }; group.Attributes.Add(attribute4); XmlSchemaAttribute attribute5 = new XmlSchemaAttribute { RefName = new XmlQualifiedName("space", "http://www.w3.org/XML/1998/namespace") }; group.Attributes.Add(attribute5); XmlSchemaAttribute attribute6 = new XmlSchemaAttribute { RefName = new XmlQualifiedName("base", "http://www.w3.org/XML/1998/namespace") }; group.Attributes.Add(attribute6); schema.Items.Add(group); schema.IsPreprocessed = true; schema.CompileSchemaInSet(new NameTable(), null, null); Interlocked.CompareExchange<XmlSchema>(ref builtInSchemaForXmlNS, schema, null); } return builtInSchemaForXmlNS; }
void ImportAttributeGroupMembers(XmlSchemaAttributeGroup group, string identifier, CodeIdentifiers members, string ns) { for (int i = 0; i < group.Attributes.Count; i++) { object item = group.Attributes[i]; if (item is XmlSchemaAttributeGroup) ImportAttributeGroupMembers((XmlSchemaAttributeGroup)item, identifier, members, ns); else if (item is XmlSchemaAttribute) ImportAttributeMember((XmlSchemaAttribute)item, identifier, members, ns); } if (group.AnyAttribute != null) ImportAnyAttributeMember(group.AnyAttribute, members); }
private void CheckRefinedAttributeGroup(XmlSchemaAttributeGroup attributeGroup) { int num = 0; for (int i = 0; i < attributeGroup.Attributes.Count; i++) { XmlSchemaAttributeGroupRef ref2 = attributeGroup.Attributes[i] as XmlSchemaAttributeGroupRef; if ((ref2 != null) && (ref2.RefName == attributeGroup.QualifiedName)) { num++; } } if (num > 1) { base.SendValidationEvent("Sch_MultipleAttrGroupSelfRef", attributeGroup); } attributeGroup.SelfReferenceCount = num; }
public static int ValidateAttributesResolved(XmlSchemaObjectTable attributesResolved, ValidationEventHandler h, XmlSchema schema, XmlSchemaObjectCollection attributes, XmlSchemaAnyAttribute anyAttribute, ref XmlSchemaAnyAttribute anyAttributeUse, XmlSchemaAttributeGroup redefined, bool skipEquivalent) { int num = 0; if (anyAttribute != null && anyAttributeUse == null) { anyAttributeUse = anyAttribute; } ArrayList arrayList = new ArrayList(); foreach (XmlSchemaObject xmlSchemaObject in attributes) { XmlSchemaAttributeGroupRef xmlSchemaAttributeGroupRef = xmlSchemaObject as XmlSchemaAttributeGroupRef; if (xmlSchemaAttributeGroupRef != null) { XmlSchemaAttributeGroup xmlSchemaAttributeGroup = null; if (redefined != null && xmlSchemaAttributeGroupRef.RefName == redefined.QualifiedName) { xmlSchemaAttributeGroup = redefined; } else { xmlSchemaAttributeGroup = schema.FindAttributeGroup(xmlSchemaAttributeGroupRef.RefName); } if (xmlSchemaAttributeGroup == null) { if (!schema.missedSubComponents) { xmlSchemaAttributeGroupRef.error(h, "Referenced attribute group " + xmlSchemaAttributeGroupRef.RefName + " was not found in the corresponding schema."); } } else if (xmlSchemaAttributeGroup.AttributeGroupRecursionCheck) { xmlSchemaAttributeGroup.error(h, "Attribute group recursion was found: " + xmlSchemaAttributeGroupRef.RefName); } else { try { xmlSchemaAttributeGroup.AttributeGroupRecursionCheck = true; num += xmlSchemaAttributeGroup.Validate(h, schema); } finally { xmlSchemaAttributeGroup.AttributeGroupRecursionCheck = false; } if (xmlSchemaAttributeGroup.AnyAttributeUse != null && anyAttribute == null) { anyAttributeUse = xmlSchemaAttributeGroup.AnyAttributeUse; } foreach (object obj in xmlSchemaAttributeGroup.AttributeUses) { XmlSchemaAttribute xmlSchemaAttribute = (XmlSchemaAttribute)((DictionaryEntry)obj).Value; if (!XmlSchemaUtil.StrictMsCompliant || xmlSchemaAttribute.Use != XmlSchemaUse.Prohibited) { if (xmlSchemaAttribute.RefName != null && xmlSchemaAttribute.RefName != XmlQualifiedName.Empty && (!skipEquivalent || !XmlSchemaUtil.AreAttributesEqual(xmlSchemaAttribute, attributesResolved[xmlSchemaAttribute.RefName] as XmlSchemaAttribute))) { XmlSchemaUtil.AddToTable(attributesResolved, xmlSchemaAttribute, xmlSchemaAttribute.RefName, h); } else if (!skipEquivalent || !XmlSchemaUtil.AreAttributesEqual(xmlSchemaAttribute, attributesResolved[xmlSchemaAttribute.QualifiedName] as XmlSchemaAttribute)) { XmlSchemaUtil.AddToTable(attributesResolved, xmlSchemaAttribute, xmlSchemaAttribute.QualifiedName, h); } } } } } else { XmlSchemaAttribute xmlSchemaAttribute2 = xmlSchemaObject as XmlSchemaAttribute; if (xmlSchemaAttribute2 != null) { num += xmlSchemaAttribute2.Validate(h, schema); if (arrayList.Contains(xmlSchemaAttribute2.QualifiedName)) { xmlSchemaAttribute2.error(h, string.Format("Duplicate attributes was found for '{0}'", xmlSchemaAttribute2.QualifiedName)); } arrayList.Add(xmlSchemaAttribute2.QualifiedName); if (!XmlSchemaUtil.StrictMsCompliant || xmlSchemaAttribute2.Use != XmlSchemaUse.Prohibited) { if (xmlSchemaAttribute2.RefName != null && xmlSchemaAttribute2.RefName != XmlQualifiedName.Empty && (!skipEquivalent || !XmlSchemaUtil.AreAttributesEqual(xmlSchemaAttribute2, attributesResolved[xmlSchemaAttribute2.RefName] as XmlSchemaAttribute))) { XmlSchemaUtil.AddToTable(attributesResolved, xmlSchemaAttribute2, xmlSchemaAttribute2.RefName, h); } else if (!skipEquivalent || !XmlSchemaUtil.AreAttributesEqual(xmlSchemaAttribute2, attributesResolved[xmlSchemaAttribute2.QualifiedName] as XmlSchemaAttribute)) { XmlSchemaUtil.AddToTable(attributesResolved, xmlSchemaAttribute2, xmlSchemaAttribute2.QualifiedName, h); } } } else if (anyAttribute == null) { anyAttributeUse = (XmlSchemaAnyAttribute)xmlSchemaObject; anyAttribute.Validate(h, schema); } } } return(num); }