Summary description for XmlSchemaAttribute.
상속: XmlSchemaAnnotated
예제 #1
0
        protected void BuildAttribute( XmlSchemaAttribute attribute,
                                       ObjectDef objectDef )
        {
            FieldDef def = null;
            bool isEnum;
            string dataType =
                GetClassTypeFromDataType
                    ( attribute.AttributeSchemaType, attribute.QualifiedName.Name, objectDef.Name,
                      out isEnum );
            if ( isEnum ) {
                def = objectDef.DefineAttr( attribute.QualifiedName.Name, null );
                def.SetEnum( dataType );
            }
            else {
                def = objectDef.DefineAttr( attribute.QualifiedName.Name, dataType );
            }

            if ( attribute.Use == XmlSchemaUse.Required ) {
                def.SetFlags( "R" );
            }
            else {
                def.SetFlags( "O" );
            }
            setAnnotation( def, attribute.Annotation );
            // TODO: See if the data type is an enumeration
            //System.Diagnostics.Debug.Assert( ! ( attribute.AttributeType is xmlschemdata
        }
		public static XmlSchemaElement AndSchema()
		{
			var type = new XmlSchemaComplexType();

			var any = new XmlSchemaAny();
			any.MinOccurs = 1;
			any.MaxOccursString = "unbounded";
			any.ProcessContents = XmlSchemaContentProcessing.Strict;
			any.Namespace = "##local";

			var sequence = new XmlSchemaSequence();
			type.Particle = sequence;
			sequence.Items.Add(any);

			var attrib = new XmlSchemaAttribute();
			attrib.Name = "expressionLanguage";
			attrib.Use = XmlSchemaUse.Optional;
			attrib.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
			type.Attributes.Add(attrib);

			attrib = new XmlSchemaAttribute();
			attrib.Name = "failMessage";
			attrib.Use = XmlSchemaUse.Optional;
			attrib.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
			type.Attributes.Add(attrib);

			var element = new XmlSchemaElement();
			element.Name = "and";
			element.SchemaType = type;

			return element;
		}
예제 #3
0
 public static void ReplaceThisWith(this XmlSchemaAttribute that, XmlSchemaAttribute with) 
 {
     var gr = that.Parent as XmlSchemaComplexType;
     int idx = gr.Attributes.IndexOf(that);
     gr.Attributes.Insert(idx, with);
     gr.Attributes.Remove(that);
 }
 private XmlSchemaForm AttributeForm(string ns, XmlSchemaAttribute attribute)
 {
     if (attribute.Form != XmlSchemaForm.None)
     {
         return attribute.Form;
     }
     XmlSchemaObject parent = attribute;
     while (parent.Parent != null)
     {
         parent = parent.Parent;
     }
     XmlSchema schema = parent as XmlSchema;
     if (schema != null)
     {
         if ((ns == null) || (ns.Length == 0))
         {
             if (schema.AttributeFormDefault != XmlSchemaForm.None)
             {
                 return schema.AttributeFormDefault;
             }
             return XmlSchemaForm.Unqualified;
         }
         XmlSchemas.Preprocess(schema);
         if ((attribute.QualifiedName.Namespace != null) && (attribute.QualifiedName.Namespace.Length != 0))
         {
             return XmlSchemaForm.Qualified;
         }
     }
     return XmlSchemaForm.Unqualified;
 }
예제 #5
0
        protected override void Visit(XmlSchemaAttribute attribute)
        {
            if (!attribute.RefName.IsEmpty ||
                attribute.Use == XmlSchemaUse.Prohibited)
                return;

            AddTopic(TopicType.Attribute, attribute.QualifiedName.Namespace, attribute, attribute.Name);
        }
		public override void FixtureInit()
		{
			XmlSchemaCompletionCollection schemas = new XmlSchemaCompletionCollection();
			schemas.Add(SchemaCompletion);
			string xml = "<note xmlns='http://www.w3schools.com' name=''></note>";
			XmlSchemaDefinition schemaDefinition = new XmlSchemaDefinition(schemas, null);
			schemaAttribute = (XmlSchemaAttribute)schemaDefinition.GetSelectedSchemaObject(xml, xml.IndexOf("name"));
		}
		public override void FixtureInit()
		{
			XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection();
			schemas.Add(SchemaCompletionData);
			XmlCompletionDataProvider provider = new XmlCompletionDataProvider(schemas, SchemaCompletionData, String.Empty);
			string xml = "<note xmlns='http://www.w3schools.com' name=''></note>";
			schemaAttribute = (XmlSchemaAttribute)XmlView.GetSchemaObjectSelected(xml, xml.IndexOf("name"), provider);
		}
예제 #8
0
        protected override void Visit(XmlSchemaAttribute attribute)
        {
            if (!attribute.RefName.IsEmpty)
                return;

            PushNamedObject(attribute);
            base.Visit(attribute);
            PopNamedObject();
        }
		public override void FixtureInit()
		{
			XmlElementPath path = new XmlElementPath();
			path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com"));
			
			XmlSchemaElement element = SchemaCompletionData.FindElement(path);
			attribute = SchemaCompletionData.FindAttribute(element, "name");
			missingAttribute = SchemaCompletionData.FindAttribute(element, "missing");
		}
 internal void Clear()
 {
     this.isNil = false;
     this.isDefault = false;
     this.schemaType = null;
     this.schemaElement = null;
     this.schemaAttribute = null;
     this.memberType = null;
     this.validity = XmlSchemaValidity.NotKnown;
     this.contentType = XmlSchemaContentType.Empty;
 }
		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=\"dir\"");
			index = xml.IndexOf("dir", index);
			XmlSchemaDefinition schemaDefinition = new XmlSchemaDefinition(schemas, SchemaCompletion);
			schemaAttribute = (XmlSchemaAttribute)schemaDefinition.GetSelectedSchemaObject(xml, index);
		}
		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=\"dir\"");
			index = xml.IndexOf("dir", index);
			schemaAttribute = (XmlSchemaAttribute)XmlView.GetSchemaObjectSelected(xml, index, provider, SchemaCompletionData);
		}
		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, null);
			
			string xml = GetSchema();
			schemaAttribute = (XmlSchemaAttribute)XmlEditorView.GetSchemaObjectSelected(xml, xml.IndexOf("ref=\"name"), provider, SchemaCompletionData);
			
			int index = xml.IndexOf("ref=\"name");
			index = xml.IndexOf('n', index);
			referencedSchemaElement = (XmlSchemaElement)XmlEditorView.GetSchemaObjectSelected(xml, index, provider, SchemaCompletionData);
		}
예제 #14
0
        public XmlSchema GetDataSchemas(XmlSchema querySchema,IEnumerable<Registration> registrations)
        {
            var schema = new XmlSchema { TargetNamespace = RegistrationStorage.Dataspace };
            schema.Namespaces.Add("", RegistrationStorage.Dataspace);
            var guid = CreateGuidType();
            schema.Items.Add(guid);
            schema.Includes.Add(new XmlSchemaImport { Schema = querySchema, Namespace = querySchema.TargetNamespace });
            foreach (var registration in registrations)
            {
                var etype = new XmlSchemaComplexType
                {
                    Name = registration.ResourceName,
                    Annotation = new XmlSchemaAnnotation()
                };
                var doc = new XmlSchemaDocumentation { Markup = TextToNode(registration.ResourceType.FullName) };
                etype.Annotation.Items.Add(doc);
                etype.Block = XmlSchemaDerivationMethod.Extension;
                var idAttr = new XmlSchemaAttribute
                {
                    Name = "Id",
                    SchemaTypeName = new XmlQualifiedName(guid.Name, RegistrationStorage.Dataspace),
                    Use = XmlSchemaUse.Required
                };
                etype.Attributes.Add(idAttr);
                var noChildrenAttr = new XmlSchemaAttribute
                {
                    Name = RegistrationStorage.DefinitlyNoChildren,
                    SchemaType = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Boolean),
                    Use = XmlSchemaUse.Optional
                };
                etype.Attributes.Add(noChildrenAttr);
                if (querySchema.Items.OfType<XmlSchemaAttributeGroup>().Any(k => k.Name == etype.Name))
                {

                    var group = new XmlSchemaAttributeGroupRef();
                    group.RefName = new XmlQualifiedName(etype.Name.Replace(" ", "_"), querySchema.TargetNamespace);
                    etype.Attributes.Add(group);

                }
                schema.Items.Add(etype);
            }

            return schema;
        }
예제 #15
0
파일: XsdVisitor.cs 프로젝트: willrawls/arp
        public virtual void VisitXmlSchemaAttribute(XmlSchemaAttribute attribute)
        {
            Dispatch(attribute.AttributeSchemaType);

            // why there is no pattern mathing in C# ???

            if(attribute.Parent is XmlSchemaComplexType)
            {
                XmlSchemaComplexType complexType = (XmlSchemaComplexType) attribute.Parent;

                VisitXmlSchemaAttribute(complexType, attribute);
            }
            else if (attribute.Parent is XmlSchemaAttributeGroup)
            {
                XmlSchemaAttributeGroup attributeGroup = (XmlSchemaAttributeGroup)attribute.Parent;

                VisitXmlSchemaAttribute(attributeGroup, attribute);
            }
            else
            {
                Assert.Fail(attribute.Parent.GetType().ToString());
            }
        }
예제 #16
0
		public void AddAttribute (XmlSchemaAttribute attribute)
		{
			string name = attribute.Name;
			if (name == null) {
				var ns = attribute.RefName.Namespace;
				if (string.IsNullOrEmpty (ns))
					return;
				var prefix = nsMap.GetPrefix (ns);
				if (prefix == null) {
					if (ns == "http://www.w3.org/XML/1998/namespace")
						prefix = "xml";
					else
						return;
				}
				name = attribute.RefName.Name;
				if (prefix.Length > 0)
					name = prefix + ":" + name;
			}
			if (!names.Add (name))
				return;
			string documentation = GetDocumentation (attribute.Annotation);
			Add (new XmlCompletionData (name, documentation, XmlCompletionData.DataType.XmlAttribute));
		}
        internal static XmlSchemaComplexContentExtension Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaComplexContentExtension xmlSchemaComplexContentExtension = new XmlSchemaComplexContentExtension();

            reader.MoveToElement();
            if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "extension")
            {
                XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaComplexContentExtension.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }
            xmlSchemaComplexContentExtension.LineNumber   = reader.LineNumber;
            xmlSchemaComplexContentExtension.LinePosition = reader.LinePosition;
            xmlSchemaComplexContentExtension.SourceUri    = reader.BaseURI;
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "base")
                {
                    Exception ex;
                    xmlSchemaComplexContentExtension.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader, out ex);
                    if (ex != null)
                    {
                        XmlSchemaObject.error(h, reader.Value + " is not a valid value for base attribute", ex);
                    }
                }
                else if (reader.Name == "id")
                {
                    xmlSchemaComplexContentExtension.Id = 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 extension", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaComplexContentExtension);
                }
            }
            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(xmlSchemaComplexContentExtension);
            }
            int num = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != "extension")
                    {
                        XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaComplexContentExtension.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (num <= 1 && reader.LocalName == "annotation")
                {
                    num = 2;
                    XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h);
                    if (xmlSchemaAnnotation != null)
                    {
                        xmlSchemaComplexContentExtension.Annotation = xmlSchemaAnnotation;
                    }
                }
                else
                {
                    if (num <= 2)
                    {
                        if (reader.LocalName == "group")
                        {
                            num = 3;
                            XmlSchemaGroupRef xmlSchemaGroupRef = XmlSchemaGroupRef.Read(reader, h);
                            if (xmlSchemaGroupRef != null)
                            {
                                xmlSchemaComplexContentExtension.particle = xmlSchemaGroupRef;
                            }
                            continue;
                        }
                        if (reader.LocalName == "all")
                        {
                            num = 3;
                            XmlSchemaAll xmlSchemaAll = XmlSchemaAll.Read(reader, h);
                            if (xmlSchemaAll != null)
                            {
                                xmlSchemaComplexContentExtension.particle = xmlSchemaAll;
                            }
                            continue;
                        }
                        if (reader.LocalName == "choice")
                        {
                            num = 3;
                            XmlSchemaChoice xmlSchemaChoice = XmlSchemaChoice.Read(reader, h);
                            if (xmlSchemaChoice != null)
                            {
                                xmlSchemaComplexContentExtension.particle = xmlSchemaChoice;
                            }
                            continue;
                        }
                        if (reader.LocalName == "sequence")
                        {
                            num = 3;
                            XmlSchemaSequence xmlSchemaSequence = XmlSchemaSequence.Read(reader, h);
                            if (xmlSchemaSequence != null)
                            {
                                xmlSchemaComplexContentExtension.particle = xmlSchemaSequence;
                            }
                            continue;
                        }
                    }
                    if (num <= 3)
                    {
                        if (reader.LocalName == "attribute")
                        {
                            num = 3;
                            XmlSchemaAttribute xmlSchemaAttribute = XmlSchemaAttribute.Read(reader, h);
                            if (xmlSchemaAttribute != null)
                            {
                                xmlSchemaComplexContentExtension.Attributes.Add(xmlSchemaAttribute);
                            }
                            continue;
                        }
                        if (reader.LocalName == "attributeGroup")
                        {
                            num = 3;
                            XmlSchemaAttributeGroupRef xmlSchemaAttributeGroupRef = XmlSchemaAttributeGroupRef.Read(reader, h);
                            if (xmlSchemaAttributeGroupRef != null)
                            {
                                xmlSchemaComplexContentExtension.attributes.Add(xmlSchemaAttributeGroupRef);
                            }
                            continue;
                        }
                    }
                    if (num <= 4 && reader.LocalName == "anyAttribute")
                    {
                        num = 5;
                        XmlSchemaAnyAttribute xmlSchemaAnyAttribute = XmlSchemaAnyAttribute.Read(reader, h);
                        if (xmlSchemaAnyAttribute != null)
                        {
                            xmlSchemaComplexContentExtension.AnyAttribute = xmlSchemaAnyAttribute;
                        }
                    }
                    else
                    {
                        reader.RaiseInvalidElementError();
                    }
                }
            }
            return(xmlSchemaComplexContentExtension);
        }
        //<extension
        //base = QName
        //id = ID
        //{any attributes with non-schema namespace . . .}>
        //Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?))
        //</extension>
        internal static XmlSchemaSimpleContentExtension Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaSimpleContentExtension extension = new XmlSchemaSimpleContentExtension();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
            {
                error(h, "Should not happen :1: XmlSchemaAttributeGroup.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }

            extension.LineNumber   = reader.LineNumber;
            extension.LinePosition = reader.LinePosition;
            extension.SourceUri    = reader.BaseURI;

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "base")
                {
                    Exception innerex;
                    extension.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader, out innerex);
                    if (innerex != null)
                    {
                        error(h, reader.Value + " is not a valid value for base attribute", innerex);
                    }
                }
                else if (reader.Name == "id")
                {
                    extension.Id = reader.Value;
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for extension in this context", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, extension);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(extension);
            }

            //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: XmlSchemaSimpleContentExtension.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)
                    {
                        extension.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2)
                {
                    if (reader.LocalName == "attribute")
                    {
                        level = 2;
                        XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader, h);
                        if (attr != null)
                        {
                            extension.Attributes.Add(attr);
                        }
                        continue;
                    }
                    if (reader.LocalName == "attributeGroup")
                    {
                        level = 2;
                        XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader, h);
                        if (attr != null)
                        {
                            extension.attributes.Add(attr);
                        }
                        continue;
                    }
                }
                if (level <= 3 && reader.LocalName == "anyAttribute")
                {
                    level = 4;
                    XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader, h);
                    if (anyattr != null)
                    {
                        extension.AnyAttribute = anyattr;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(extension);
        }
 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
 {
     if (this.CompilationId == schema.CompilationId)
     {
         return(0);
     }
     if (this.isRedefinedComponent)
     {
         if (base.Annotation != null)
         {
             base.Annotation.isRedefinedComponent = true;
         }
         if (this.AnyAttribute != null)
         {
             this.AnyAttribute.isRedefinedComponent = true;
         }
         foreach (XmlSchemaObject xmlSchemaObject in this.Attributes)
         {
             xmlSchemaObject.isRedefinedComponent = true;
         }
         if (this.Particle != null)
         {
             this.Particle.isRedefinedComponent = true;
         }
     }
     if (this.BaseTypeName == null || this.BaseTypeName.IsEmpty)
     {
         base.error(h, "base must be present, as a QName");
     }
     else if (!XmlSchemaUtil.CheckQName(this.BaseTypeName))
     {
         base.error(h, "BaseTypeName is not a valid XmlQualifiedName");
     }
     if (this.AnyAttribute != null)
     {
         this.errorCount += this.AnyAttribute.Compile(h, schema);
     }
     foreach (XmlSchemaObject xmlSchemaObject2 in this.Attributes)
     {
         if (xmlSchemaObject2 is XmlSchemaAttribute)
         {
             XmlSchemaAttribute xmlSchemaAttribute = (XmlSchemaAttribute)xmlSchemaObject2;
             this.errorCount += xmlSchemaAttribute.Compile(h, schema);
         }
         else if (xmlSchemaObject2 is XmlSchemaAttributeGroupRef)
         {
             XmlSchemaAttributeGroupRef xmlSchemaAttributeGroupRef = (XmlSchemaAttributeGroupRef)xmlSchemaObject2;
             this.errorCount += xmlSchemaAttributeGroupRef.Compile(h, schema);
         }
         else
         {
             base.error(h, xmlSchemaObject2.GetType() + " is not valid in this place::ComplexConetnetExtension");
         }
     }
     if (this.Particle != null)
     {
         if (this.Particle is XmlSchemaGroupRef)
         {
             this.errorCount += ((XmlSchemaGroupRef)this.Particle).Compile(h, schema);
         }
         else if (this.Particle is XmlSchemaAll)
         {
             this.errorCount += ((XmlSchemaAll)this.Particle).Compile(h, schema);
         }
         else if (this.Particle is XmlSchemaChoice)
         {
             this.errorCount += ((XmlSchemaChoice)this.Particle).Compile(h, schema);
         }
         else if (this.Particle is XmlSchemaSequence)
         {
             this.errorCount += ((XmlSchemaSequence)this.Particle).Compile(h, schema);
         }
         else
         {
             base.error(h, "Particle of a restriction is limited only to group, sequence, choice and all.");
         }
     }
     XmlSchemaUtil.CompileID(base.Id, this, schema.IDCollection, h);
     this.CompilationId = schema.CompilationId;
     return(this.errorCount);
 }
        internal static XmlSchemaSimpleContentRestriction Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaSimpleContentRestriction xmlSchemaSimpleContentRestriction = new XmlSchemaSimpleContentRestriction();

            reader.MoveToElement();
            if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "restriction")
            {
                XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaComplexContentRestriction.Read, name=" + reader.Name, null);
                reader.SkipToEnd();
                return(null);
            }
            xmlSchemaSimpleContentRestriction.LineNumber   = reader.LineNumber;
            xmlSchemaSimpleContentRestriction.LinePosition = reader.LinePosition;
            xmlSchemaSimpleContentRestriction.SourceUri    = reader.BaseURI;
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "base")
                {
                    Exception ex;
                    xmlSchemaSimpleContentRestriction.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader, out ex);
                    if (ex != null)
                    {
                        XmlSchemaObject.error(h, reader.Value + " is not a valid value for base attribute", ex);
                    }
                }
                else if (reader.Name == "id")
                {
                    xmlSchemaSimpleContentRestriction.Id = 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 restriction", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaSimpleContentRestriction);
                }
            }
            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(xmlSchemaSimpleContentRestriction);
            }
            int num = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != "restriction")
                    {
                        XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaSimpleContentRestriction.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (num <= 1 && reader.LocalName == "annotation")
                {
                    num = 2;
                    XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h);
                    if (xmlSchemaAnnotation != null)
                    {
                        xmlSchemaSimpleContentRestriction.Annotation = xmlSchemaAnnotation;
                    }
                }
                else if (num <= 2 && reader.LocalName == "simpleType")
                {
                    num = 3;
                    XmlSchemaSimpleType xmlSchemaSimpleType = XmlSchemaSimpleType.Read(reader, h);
                    if (xmlSchemaSimpleType != null)
                    {
                        xmlSchemaSimpleContentRestriction.baseType = xmlSchemaSimpleType;
                    }
                }
                else
                {
                    if (num <= 3)
                    {
                        if (reader.LocalName == "minExclusive")
                        {
                            num = 3;
                            XmlSchemaMinExclusiveFacet xmlSchemaMinExclusiveFacet = XmlSchemaMinExclusiveFacet.Read(reader, h);
                            if (xmlSchemaMinExclusiveFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaMinExclusiveFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "minInclusive")
                        {
                            num = 3;
                            XmlSchemaMinInclusiveFacet xmlSchemaMinInclusiveFacet = XmlSchemaMinInclusiveFacet.Read(reader, h);
                            if (xmlSchemaMinInclusiveFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaMinInclusiveFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "maxExclusive")
                        {
                            num = 3;
                            XmlSchemaMaxExclusiveFacet xmlSchemaMaxExclusiveFacet = XmlSchemaMaxExclusiveFacet.Read(reader, h);
                            if (xmlSchemaMaxExclusiveFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaMaxExclusiveFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "maxInclusive")
                        {
                            num = 3;
                            XmlSchemaMaxInclusiveFacet xmlSchemaMaxInclusiveFacet = XmlSchemaMaxInclusiveFacet.Read(reader, h);
                            if (xmlSchemaMaxInclusiveFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaMaxInclusiveFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "totalDigits")
                        {
                            num = 3;
                            XmlSchemaTotalDigitsFacet xmlSchemaTotalDigitsFacet = XmlSchemaTotalDigitsFacet.Read(reader, h);
                            if (xmlSchemaTotalDigitsFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaTotalDigitsFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "fractionDigits")
                        {
                            num = 3;
                            XmlSchemaFractionDigitsFacet xmlSchemaFractionDigitsFacet = XmlSchemaFractionDigitsFacet.Read(reader, h);
                            if (xmlSchemaFractionDigitsFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaFractionDigitsFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "length")
                        {
                            num = 3;
                            XmlSchemaLengthFacet xmlSchemaLengthFacet = XmlSchemaLengthFacet.Read(reader, h);
                            if (xmlSchemaLengthFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaLengthFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "minLength")
                        {
                            num = 3;
                            XmlSchemaMinLengthFacet xmlSchemaMinLengthFacet = XmlSchemaMinLengthFacet.Read(reader, h);
                            if (xmlSchemaMinLengthFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaMinLengthFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "maxLength")
                        {
                            num = 3;
                            XmlSchemaMaxLengthFacet xmlSchemaMaxLengthFacet = XmlSchemaMaxLengthFacet.Read(reader, h);
                            if (xmlSchemaMaxLengthFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaMaxLengthFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "enumeration")
                        {
                            num = 3;
                            XmlSchemaEnumerationFacet xmlSchemaEnumerationFacet = XmlSchemaEnumerationFacet.Read(reader, h);
                            if (xmlSchemaEnumerationFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaEnumerationFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "whiteSpace")
                        {
                            num = 3;
                            XmlSchemaWhiteSpaceFacet xmlSchemaWhiteSpaceFacet = XmlSchemaWhiteSpaceFacet.Read(reader, h);
                            if (xmlSchemaWhiteSpaceFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaWhiteSpaceFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "pattern")
                        {
                            num = 3;
                            XmlSchemaPatternFacet xmlSchemaPatternFacet = XmlSchemaPatternFacet.Read(reader, h);
                            if (xmlSchemaPatternFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaPatternFacet);
                            }
                            continue;
                        }
                    }
                    if (num <= 4)
                    {
                        if (reader.LocalName == "attribute")
                        {
                            num = 4;
                            XmlSchemaAttribute xmlSchemaAttribute = XmlSchemaAttribute.Read(reader, h);
                            if (xmlSchemaAttribute != null)
                            {
                                xmlSchemaSimpleContentRestriction.Attributes.Add(xmlSchemaAttribute);
                            }
                            continue;
                        }
                        if (reader.LocalName == "attributeGroup")
                        {
                            num = 4;
                            XmlSchemaAttributeGroupRef xmlSchemaAttributeGroupRef = XmlSchemaAttributeGroupRef.Read(reader, h);
                            if (xmlSchemaAttributeGroupRef != null)
                            {
                                xmlSchemaSimpleContentRestriction.attributes.Add(xmlSchemaAttributeGroupRef);
                            }
                            continue;
                        }
                    }
                    if (num <= 5 && reader.LocalName == "anyAttribute")
                    {
                        num = 6;
                        XmlSchemaAnyAttribute xmlSchemaAnyAttribute = XmlSchemaAnyAttribute.Read(reader, h);
                        if (xmlSchemaAnyAttribute != null)
                        {
                            xmlSchemaSimpleContentRestriction.AnyAttribute = xmlSchemaAnyAttribute;
                        }
                    }
                    else
                    {
                        reader.RaiseInvalidElementError();
                    }
                }
            }
            return(xmlSchemaSimpleContentRestriction);
        }
        ///<remarks>
        /// 1. Base must be present and a QName
        ///</remarks>
        internal override int Compile(ValidationEventHandler h, XmlSchema schema)
        {
            // If this is already compiled this time, simply skip.
            if (CompilationId == schema.CompilationId)
            {
                return(0);
            }

            if (this.isRedefinedComponent)
            {
                if (Annotation != null)
                {
                    Annotation.isRedefinedComponent = true;
                }
                if (AnyAttribute != null)
                {
                    AnyAttribute.isRedefinedComponent = true;
                }
                foreach (XmlSchemaObject obj in Attributes)
                {
                    obj.isRedefinedComponent = true;
                }
            }

            if (BaseTypeName == null || BaseTypeName.IsEmpty)
            {
                error(h, "base must be present, as a QName");
            }
            else if (!XmlSchemaUtil.CheckQName(BaseTypeName))
            {
                error(h, "BaseTypeName must be a QName");
            }

            if (this.AnyAttribute != null)
            {
                errorCount += 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::SimpleConentExtension");
                }
            }

            XmlSchemaUtil.CompileID(Id, this, schema.IDCollection, h);

            this.CompilationId = schema.CompilationId;
            return(errorCount);
        }
예제 #22
0
        //<restriction
        //  base = QName
        //  id = ID
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))
        //</restriction>
        internal static XmlSchemaComplexContentRestriction Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaComplexContentRestriction restriction = new XmlSchemaComplexContentRestriction();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
            {
                error(h, "Should not happen :1: XmlSchemaComplexContentRestriction.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }

            restriction.LineNumber   = reader.LineNumber;
            restriction.LinePosition = reader.LinePosition;
            restriction.SourceUri    = reader.BaseURI;

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "base")
                {
                    Exception innerex;
                    restriction.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader, out innerex);
                    if (innerex != null)
                    {
                        error(h, reader.Value + " is not a valid value for base attribute", innerex);
                    }
                }
                else if (reader.Name == "id")
                {
                    restriction.Id = reader.Value;
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for restriction", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, restriction);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(restriction);
            }
            //Content: 1. annotation?,
            //			(2.(group | all | choice | sequence)?, (3.(attribute | attributeGroup)*, 4.anyAttribute?)))
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaComplexContentRestriction.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)
                    {
                        restriction.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2)
                {
                    if (reader.LocalName == "group")
                    {
                        level = 3;
                        XmlSchemaGroupRef group = XmlSchemaGroupRef.Read(reader, h);
                        if (group != null)
                        {
                            restriction.particle = group;
                        }
                        continue;
                    }
                    if (reader.LocalName == "all")
                    {
                        level = 3;
                        XmlSchemaAll all = XmlSchemaAll.Read(reader, h);
                        if (all != null)
                        {
                            restriction.particle = all;
                        }
                        continue;
                    }
                    if (reader.LocalName == "choice")
                    {
                        level = 3;
                        XmlSchemaChoice choice = XmlSchemaChoice.Read(reader, h);
                        if (choice != null)
                        {
                            restriction.particle = choice;
                        }
                        continue;
                    }
                    if (reader.LocalName == "sequence")
                    {
                        level = 3;
                        XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader, h);
                        if (sequence != null)
                        {
                            restriction.particle = sequence;
                        }
                        continue;
                    }
                }
                if (level <= 3)
                {
                    if (reader.LocalName == "attribute")
                    {
                        level = 3;
                        XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader, h);
                        if (attr != null)
                        {
                            restriction.Attributes.Add(attr);
                        }
                        continue;
                    }
                    if (reader.LocalName == "attributeGroup")
                    {
                        level = 3;
                        XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader, h);
                        if (attr != null)
                        {
                            restriction.attributes.Add(attr);
                        }
                        continue;
                    }
                }
                if (level <= 4 && reader.LocalName == "anyAttribute")
                {
                    level = 5;
                    XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader, h);
                    if (anyattr != null)
                    {
                        restriction.AnyAttribute = anyattr;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(restriction);
        }
        internal SchemaAttDef GetAttributeXsd(SchemaElementDecl ed, XmlQualifiedName qname, XmlSchemaObject partialValidationType, out AttributeMatchState attributeMatchState)
        {
            SchemaAttDef attdef = null;

            attributeMatchState = AttributeMatchState.UndeclaredAttribute;
            if (ed != null)
            {
                attdef = ed.GetAttDef(qname);
                if (attdef != null)
                {
                    attributeMatchState = AttributeMatchState.AttributeFound;
                    return(attdef);
                }
                XmlSchemaAnyAttribute any = ed.AnyAttribute;
                if (any != null)
                {
                    if (!any.NamespaceList.Allows(qname))
                    {
                        attributeMatchState = AttributeMatchState.ProhibitedAnyAttribute;
                    }
                    else if (any.ProcessContentsCorrect != XmlSchemaContentProcessing.Skip)
                    {
                        if (attributeDecls.TryGetValue(qname, out attdef))
                        {
                            if (attdef.Datatype.TypeCode == XmlTypeCode.Id)   //anyAttribute match whose type is ID
                            {
                                attributeMatchState = AttributeMatchState.AnyIdAttributeFound;
                            }
                            else
                            {
                                attributeMatchState = AttributeMatchState.AttributeFound;
                            }
                        }
                        else if (any.ProcessContentsCorrect == XmlSchemaContentProcessing.Lax)
                        {
                            attributeMatchState = AttributeMatchState.AnyAttributeLax;
                        }
                    }
                    else
                    {
                        attributeMatchState = AttributeMatchState.AnyAttributeSkip;
                    }
                }
                else if (ed.ProhibitedAttributes.ContainsKey(qname))
                {
                    attributeMatchState = AttributeMatchState.ProhibitedAttribute;
                }
            }
            else if (partialValidationType != null)
            {
                XmlSchemaAttribute attr = partialValidationType as XmlSchemaAttribute;
                if (attr != null)
                {
                    if (qname.Equals(attr.QualifiedName))
                    {
                        attdef = attr.AttDef;
                        attributeMatchState = AttributeMatchState.AttributeFound;
                    }
                    else
                    {
                        attributeMatchState = AttributeMatchState.AttributeNameMismatch;
                    }
                }
                else
                {
                    attributeMatchState = AttributeMatchState.ValidateAttributeInvalidCall;
                }
            }
            else
            {
                if (attributeDecls.TryGetValue(qname, out attdef))
                {
                    attributeMatchState = AttributeMatchState.AttributeFound;
                }
                else
                {
                    attributeMatchState = AttributeMatchState.UndeclaredElementAndAttribute;
                }
            }
            return(attdef);
        }
 private void PreprocessLocalAttribute(XmlSchemaAttribute attribute)
 {
     if (attribute.Name != null)
     {
         this.ValidateNameAttribute(attribute);
         this.PreprocessAttributeContent(attribute);
         attribute.SetQualifiedName(new XmlQualifiedName(attribute.Name, ((attribute.Form == XmlSchemaForm.Qualified) || ((attribute.Form == XmlSchemaForm.None) && (this.attributeFormDefault == XmlSchemaForm.Qualified))) ? this.targetNamespace : null));
     }
     else
     {
         this.PreprocessAnnotation(attribute);
         if (attribute.RefName.IsEmpty)
         {
             base.SendValidationEvent("Sch_AttributeNameRef", "???", attribute);
         }
         else
         {
             this.ValidateQNameAttribute(attribute, "ref", attribute.RefName);
         }
         if ((!attribute.SchemaTypeName.IsEmpty || (attribute.SchemaType != null)) || (attribute.Form != XmlSchemaForm.None))
         {
             base.SendValidationEvent("Sch_InvalidAttributeRef", attribute);
         }
         attribute.SetQualifiedName(attribute.RefName);
     }
     this.ValidateIdAttribute(attribute);
 }
 private void PreprocessAttribute(XmlSchemaAttribute attribute)
 {
     if (attribute.Name != null)
     {
         this.ValidateNameAttribute(attribute);
         attribute.SetQualifiedName(new XmlQualifiedName(attribute.Name, this.targetNamespace));
     }
     else
     {
         base.SendValidationEvent("Sch_MissRequiredAttribute", "name", attribute);
     }
     if (attribute.Use != XmlSchemaUse.None)
     {
         base.SendValidationEvent("Sch_ForbiddenAttribute", "use", attribute);
     }
     if (attribute.Form != XmlSchemaForm.None)
     {
         base.SendValidationEvent("Sch_ForbiddenAttribute", "form", attribute);
     }
     this.PreprocessAttributeContent(attribute);
     this.ValidateIdAttribute(attribute);
 }
예제 #26
0
        public void v7()
        {
            try
            {
                XmlSchemaSet sc = new XmlSchemaSet();
                XmlSchema Schema1 = sc.Add(null, TestData._XsdAuthor);
                CError.Compare(sc.Count, 1, "Count after add");
                CError.Compare(sc.Contains(Schema1), true, "Contains after add");

                sc.Compile();
                CError.Compare(sc.Count, 1, "Count");
                CError.Compare(sc.Contains(Schema1), true, "Contains");

                //edit
                XmlSchemaAttribute attributeDog = new XmlSchemaAttribute();
                Schema1.Items.Add(attributeDog);
                attributeDog.Name = "dog";
                attributeDog.SchemaTypeName = new XmlQualifiedName("blah", "http://www.w3.org/2001/XMLSchema");
                sc.Reprocess(Schema1);
                CError.Compare(sc.Count, 1, "Count");
                CError.Compare(sc.Contains(Schema1), true, "Contains");
                CError.Compare(sc.IsCompiled, false, "IsCompiled");
                sc.Compile();
                CError.Compare(sc.IsCompiled, true, "IsCompiled");
                CError.Compare(Schema1.IsCompiled, true, "IsCompiled on SOM");
            }
            catch (XmlSchemaException e)
            {
                _output.WriteLine(e.ToString());
                return;
            }
            Assert.True(false);
        }
예제 #27
0
        /// <remarks>
        /// 1. base must be present
        /// </remarks>
        internal override int Compile(ValidationEventHandler h, XmlSchema schema)
        {
            // If this is already compiled this time, simply skip.
            if (CompilationId == schema.CompilationId)
            {
                return(0);
            }

            if (this.isRedefinedComponent)
            {
                if (Annotation != null)
                {
                    Annotation.isRedefinedComponent = true;
                }
                if (AnyAttribute != null)
                {
                    AnyAttribute.isRedefinedComponent = true;
                }
                foreach (XmlSchemaObject obj in Attributes)
                {
                    obj.isRedefinedComponent = true;
                }
                if (Particle != null)
                {
                    Particle.isRedefinedComponent = true;
                }
            }

            if (BaseTypeName == null || BaseTypeName.IsEmpty)
            {
                error(h, "base must be present, as a QName");
            }
            else if (!XmlSchemaUtil.CheckQName(BaseTypeName))
            {
                error(h, "BaseTypeName is not a valid XmlQualifiedName");
            }

            if (this.AnyAttribute != null)
            {
                errorCount += 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::ComplexContentRestriction");
                }
            }

            if (Particle != null)
            {
                if (Particle is XmlSchemaGroupRef)
                {
                    errorCount += ((XmlSchemaGroupRef)Particle).Compile(h, schema);
                }
                else if (Particle is XmlSchemaAll)
                {
                    errorCount += ((XmlSchemaAll)Particle).Compile(h, schema);
                }
                else if (Particle is XmlSchemaChoice)
                {
                    errorCount += ((XmlSchemaChoice)Particle).Compile(h, schema);
                }
                else if (Particle is XmlSchemaSequence)
                {
                    errorCount += ((XmlSchemaSequence)Particle).Compile(h, schema);
                }
                else
                {
                    error(h, "Particle of a restriction is limited only to group, sequence, choice and all.");
                }
            }

            XmlSchemaUtil.CompileID(Id, this, schema.IDCollection, h);

            this.CompilationId = schema.CompilationId;
            return(errorCount);
        }
예제 #28
0
        private void InferAttributes(Element el, string ns, bool isNew)
        {
            // Now this element is going to have complexType.
            // It currently not, then we have to replace it.
            ComplexType ct      = null;
            SOMList     attList = null;
            Hashtable   table   = null;

            do
            {
                switch (source.NamespaceURI)
                {
                case NamespaceXml:
                    if (schemas.Schemas(
                            NamespaceXml).Count == 0)
                    {
                        IncludeXmlAttributes();
                    }
                    break;

                case XmlSchema.InstanceNamespace:
                    if (source.LocalName == "nil")
                    {
                        el.IsNillable = true;
                    }
                    // all other xsi:* atts are ignored
                    continue;

                case NamespaceXmlns:
                    continue;
                }
                if (ct == null)
                {
                    ct      = ToComplexType(el);
                    attList = GetAttributes(ct);
                    table   = CollectAttrTable(attList);
                }
                QName attrName = new QName(
                    source.LocalName, source.NamespaceURI);
                Attr attr = table [attrName] as Attr;
                if (attr == null)
                {
                    attList.Add(InferNewAttribute(
                                    attrName, isNew, ns));
                }
                else
                {
                    table.Remove(attrName);
                    if (attr.RefName != null &&
                        attr.RefName != QName.Empty)
                    {
                        continue;                         // just a reference
                    }
                    InferMergedAttribute(attr);
                }
            } while (source.MoveToNextAttribute());

            // mark all attr definitions that did not appear
            // as optional.
            if (table != null)
            {
                foreach (Attr attr in table.Values)
                {
                    attr.Use = Use.Optional;
                }
            }
        }
 private static void CleanupAttribute(XmlSchemaAttribute attribute)
 {
     if (attribute.SchemaType != null)
     {
         CleanupSimpleType(attribute.SchemaType);
     }
     attribute.AttDef = null;
 }
예제 #30
0
		XmlSchemaAttribute FindRefAttribute (XmlQualifiedName refName)
		{
			if (refName.Namespace == XmlNamespace)
			{
				XmlSchemaAttribute at = new XmlSchemaAttribute ();
				at.Name = refName.Name;
				at.SchemaTypeName = new XmlQualifiedName ("string",XmlSchema.Namespace);
				return at;
			}
			return (XmlSchemaAttribute) schemas.Find (refName, typeof(XmlSchemaAttribute));
		}
예제 #31
0
 // validate string value agains attr and
 // if invalid, then relax the type.
 private void InferMergedAttribute(Attr attr)
 {
     attr.SchemaTypeName = InferMergedType(source.Value,
                                           attr.SchemaTypeName);
     attr.SchemaType = null;
 }
예제 #32
0
 internal static bool AreAttributesEqual(XmlSchemaAttribute one, XmlSchemaAttribute another)
 {
     return(one != null && another != null && (one.AttributeType == another.AttributeType && one.Form == another.Form && one.ValidatedUse == another.ValidatedUse && one.ValidatedDefaultValue == another.ValidatedDefaultValue) && one.ValidatedFixedValue == another.ValidatedFixedValue);
 }
예제 #33
0
            private XmlSchemaAttribute AddAttribute(string localName, string prefix, string childURI, string attrValue, bool bCreatingNewType, XmlSchema parentSchema, XmlSchemaObjectCollection addLocation, XmlSchemaObjectTable compiledAttributes)
            {
                if (childURI == XmlSchema.Namespace)
                {
                    throw new XmlSchemaInferenceException(Res.SchInf_schema, 0, 0);
                }

                XmlSchemaAttribute xsa = null;
                int AttributeType = -1;
                XmlSchemaAttribute returnedAttribute = null;    //this value will change to attributeReference if childURI!= parentURI
                XmlSchema xs = null;
                bool add = true;

                Debug.Assert(compiledAttributes != null); //AttributeUses is never null
                // First we need to look into the already compiled attributes 
                //   (they come from the schemaset which we got on input)
                // If there are none or we don't find it there, then we must search the list of attributes
                //   where we are going to add a new one (if it doesn't exist). 
                //   This is necessary to avoid adding duplicate attribute declarations.
                ICollection searchCollectionPrimary, searchCollectionSecondary;
                if (compiledAttributes.Count > 0) {
                    searchCollectionPrimary = compiledAttributes.Values;
                    searchCollectionSecondary = addLocation;
                }
                else {
                    searchCollectionPrimary = addLocation;
                    searchCollectionSecondary = null;
                }
                if (childURI == XmlReservedNs.NsXml)
                {
                    XmlSchemaAttribute attributeReference = null;
                    //see if the reference exists
                    attributeReference = FindAttributeRef(searchCollectionPrimary, localName, childURI);
                    if (attributeReference == null && searchCollectionSecondary != null) {
                        attributeReference = FindAttributeRef(searchCollectionSecondary, localName, childURI);
                    }
                    if (attributeReference == null)
                    {
                        attributeReference = new XmlSchemaAttribute();
                        attributeReference.RefName = new XmlQualifiedName(localName, childURI);
                        if (bCreatingNewType && this.Occurrence == InferenceOption.Restricted)
                        {
                            attributeReference.Use = XmlSchemaUse.Required;
                        }
                        else
                        {
                            attributeReference.Use = XmlSchemaUse.Optional;
                        }

                        addLocation.Add(attributeReference);
                    }
                    returnedAttribute = attributeReference;
                }
                else
                {
                    if (childURI.Length == 0)
                    {
                        xs = parentSchema;
                        add = false;
                    }
                    else if (childURI != null && !schemaSet.Contains(childURI))
                    {
                        /*if (parentSchema.AttributeFormDefault = XmlSchemaForm.Unqualified && childURI.Length == 0)
                    {
                        xs = parentSchema;
                        add = false;
                        break;
                    }*/
                        xs = new XmlSchema();
                        xs.AttributeFormDefault = XmlSchemaForm.Unqualified;
                        xs.ElementFormDefault = XmlSchemaForm.Qualified;
                        if (childURI.Length != 0)
                            xs.TargetNamespace = childURI;
                        //schemas.Add(childURI, xs);
                        this.schemaSet.Add(xs);
                        if (prefix.Length != 0 && String.Compare(prefix, "xml", StringComparison.OrdinalIgnoreCase) != 0)
                            NamespaceManager.AddNamespace(prefix, childURI);
                    }
                    else
                    {
                        ArrayList col = this.schemaSet.Schemas(childURI) as ArrayList;
                        if (col != null && col.Count > 0)
                        {
                            xs = col[0] as XmlSchema;
                        }

                    }
                    if (childURI.Length != 0) //
                    {
                        XmlSchemaAttribute attributeReference = null;
                        //see if the reference exists
                        attributeReference = FindAttributeRef(searchCollectionPrimary, localName, childURI);
                        if (attributeReference == null & searchCollectionSecondary != null) {
                            attributeReference = FindAttributeRef(searchCollectionSecondary, localName, childURI);
                        }
                        if (attributeReference == null)
                        {
                            attributeReference = new XmlSchemaAttribute();
                            attributeReference.RefName = new XmlQualifiedName(localName, childURI);
                            if (bCreatingNewType && this.Occurrence == InferenceOption.Restricted)
                            {
                                attributeReference.Use = XmlSchemaUse.Required;
                            }
                            else
                            {
                                attributeReference.Use = XmlSchemaUse.Optional;
                            }

                            addLocation.Add(attributeReference);
                        }
                        returnedAttribute = attributeReference;

                        //see if the attribute exists on the global level
                        xsa = FindAttribute(xs.Items, localName);
                        if (xsa == null)
                        {
                            xsa = new XmlSchemaAttribute();
                            xsa.Name = localName;
                            xsa.SchemaTypeName = RefineSimpleType(attrValue, ref AttributeType);
                            xsa.LineNumber = AttributeType; //we use LineNumber to store flags of valid types
                            xs.Items.Add(xsa);

                        }
                        else
                        {
                            if (xsa.Parent == null)
                            {
                                AttributeType = xsa.LineNumber; // we use LineNumber to store flags of valid types
                            }
                            else
                            {
                                AttributeType = GetSchemaType(xsa.SchemaTypeName);
                                xsa.Parent = null;
                            }
                            xsa.SchemaTypeName = RefineSimpleType(attrValue, ref AttributeType);
                            xsa.LineNumber = AttributeType; // we use LineNumber to store flags of valid types
                        }
                    }
                    else
                    {
                        xsa = FindAttribute(searchCollectionPrimary, localName);
                        if (xsa == null && searchCollectionSecondary != null) {
                            xsa = FindAttribute(searchCollectionSecondary, localName);
                        }
                        if (xsa == null)
                        {
                            xsa = new XmlSchemaAttribute();
                            xsa.Name = localName;
                            xsa.SchemaTypeName = RefineSimpleType(attrValue, ref AttributeType);
                            xsa.LineNumber = AttributeType; // we use LineNumber to store flags of valid types
                            if (bCreatingNewType && this.Occurrence == InferenceOption.Restricted)
                                xsa.Use = XmlSchemaUse.Required;
                            else
                                xsa.Use = XmlSchemaUse.Optional;
                            addLocation.Add(xsa);
                            if (xs.AttributeFormDefault != XmlSchemaForm.Unqualified)
                            {
                                xsa.Form = XmlSchemaForm.Unqualified;
                            }
                        }
                        else
                        {
                            if (xsa.Parent == null)
                            {
                                AttributeType = xsa.LineNumber; // we use LineNumber to store flags of valid types
                            }
                            else
                            {
                                AttributeType = GetSchemaType(xsa.SchemaTypeName);
                                xsa.Parent = null;
                            }
                            xsa.SchemaTypeName = RefineSimpleType(attrValue, ref AttributeType);
                            xsa.LineNumber = AttributeType; // we use LineNumber to store flags of valid types
                        }
                        returnedAttribute = xsa;
                    }
                }
                string nullString = null;
                if (add && childURI != parentSchema.TargetNamespace)
                {
                    for (int i = 0; i < parentSchema.Includes.Count; ++i)
                    {
                        XmlSchemaImport import = parentSchema.Includes[i] as XmlSchemaImport;
                        if (import == null)
                        {
                            continue;
                        }
                        if (import.Namespace == childURI)
                        {
                            add = false;
                        }
                    }
                    if (add)
                    {
                        XmlSchemaImport import = new XmlSchemaImport();
                        import.Schema = xs;
                        if (childURI.Length != 0)
                        {
                            nullString = childURI;
                        }
                        import.Namespace = nullString;
                        parentSchema.Includes.Add(import);
                    }
                }


                return returnedAttribute;
            }
예제 #34
0
        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);
        }
예제 #35
0
		TypeData GetAttributeTypeData (XmlQualifiedName typeQName, XmlSchemaAttribute attr)
		{
			bool sharedAnnType = false;

			if (!attr.RefName.IsEmpty) {
				XmlSchemaAttribute refAtt = FindRefAttribute (attr.RefName);
				if (refAtt == null) throw new InvalidOperationException ("Global attribute not found: " + attr.RefName);
				attr = refAtt;
				sharedAnnType = true;
			}
			
			if (!attr.SchemaTypeName.IsEmpty) return GetTypeData (attr.SchemaTypeName, null, false);
			if (attr.SchemaType == null) return TypeTranslator.GetTypeData (typeof(string));
			else return GetTypeData (attr.SchemaType, typeQName, attr.Name, sharedAnnType, null);
		}
예제 #36
0
        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);
                }
            }
        }
        void Write1_XmlSchemaAttribute(XmlSchemaAttribute o) {
            if ((object)o == null) return;
            WriteStartElement("attribute");
            WriteAttribute(@"id", @"", ((System.String)o.@Id));
            WriteAttributes((XmlAttribute[])o.@UnhandledAttributes, o);
            WriteAttribute(@"default", @"", ((System.String)o.@DefaultValue));
            WriteAttribute(@"fixed", @"", ((System.String)o.@FixedValue));
            if (o.Parent != null && !(o.Parent is XmlSchema)) {
                if (o.QualifiedName != null && !o.QualifiedName.IsEmpty && o.QualifiedName.Namespace != null && o.QualifiedName.Namespace.Length != 0) {
                    WriteAttribute(@"form", @"", "qualified");
                }
                else {
                    WriteAttribute(@"form", @"", "unqualified");
                }
            }
            WriteAttribute(@"name", @"", ((System.String)o.@Name));

            if (!o.RefName.IsEmpty) {
                WriteAttribute("ref", "", o.RefName);
            }
            else if (!o.SchemaTypeName.IsEmpty) {
                WriteAttribute("type", "", o.SchemaTypeName);
            }
            XmlSchemaUse use = o.Use == XmlSchemaUse.None ? XmlSchemaUse.Optional : o.Use;
            WriteAttribute(@"use", @"", Write30_XmlSchemaUse(use));
            Write5_XmlSchemaAnnotation((XmlSchemaAnnotation)o.@Annotation);
            Write9_XmlSchemaSimpleType((XmlSchemaSimpleType)o.@SchemaType);
            WriteEndElement();
        }
        //<restriction
        //base = QName
        //id = ID
        //{any attributes with non-schema namespace . . .}>
        //Content: (annotation?, (simpleType?, (minExclusive | minInclusive | maxExclusive | maxInclusive | totalDigits | fractionDigits | length | minLength | maxLength | enumeration | whiteSpace | pattern)*)?, ((attribute | attributeGroup)*, anyAttribute?))
        //</restriction>
        internal static XmlSchemaSimpleContentRestriction Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaSimpleContentRestriction restriction = new XmlSchemaSimpleContentRestriction();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
            {
                error(h, "Should not happen :1: XmlSchemaComplexContentRestriction.Read, name=" + reader.Name, null);
                reader.SkipToEnd();
                return(null);
            }

            restriction.LineNumber   = reader.LineNumber;
            restriction.LinePosition = reader.LinePosition;
            restriction.SourceUri    = reader.BaseURI;

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "base")
                {
                    Exception innerex;
                    restriction.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader, out innerex);
                    if (innerex != null)
                    {
                        error(h, reader.Value + " is not a valid value for base attribute", innerex);
                    }
                }
                else if (reader.Name == "id")
                {
                    restriction.Id = reader.Value;
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for restriction", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, restriction);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(restriction);
            }

            //Content:  1.annotation?,
            //		    2.simpleType?,
            //			3.(minExclusive |...| enumeration | whiteSpace | pattern)*,
            //			4.(attribute | attributeGroup)*,
            //			5.anyAttribute?
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaSimpleContentRestriction.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)
                    {
                        restriction.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2 && reader.LocalName == "simpleType")
                {
                    level = 3;
                    XmlSchemaSimpleType stype = XmlSchemaSimpleType.Read(reader, h);
                    if (stype != null)
                    {
                        restriction.baseType = stype;
                    }
                    continue;
                }
                if (level <= 3)
                {
                    if (reader.LocalName == "minExclusive")
                    {
                        level = 3;
                        XmlSchemaMinExclusiveFacet minex = XmlSchemaMinExclusiveFacet.Read(reader, h);
                        if (minex != null)
                        {
                            restriction.facets.Add(minex);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "minInclusive")
                    {
                        level = 3;
                        XmlSchemaMinInclusiveFacet mini = XmlSchemaMinInclusiveFacet.Read(reader, h);
                        if (mini != null)
                        {
                            restriction.facets.Add(mini);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "maxExclusive")
                    {
                        level = 3;
                        XmlSchemaMaxExclusiveFacet maxex = XmlSchemaMaxExclusiveFacet.Read(reader, h);
                        if (maxex != null)
                        {
                            restriction.facets.Add(maxex);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "maxInclusive")
                    {
                        level = 3;
                        XmlSchemaMaxInclusiveFacet maxi = XmlSchemaMaxInclusiveFacet.Read(reader, h);
                        if (maxi != null)
                        {
                            restriction.facets.Add(maxi);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "totalDigits")
                    {
                        level = 3;
                        XmlSchemaTotalDigitsFacet total = XmlSchemaTotalDigitsFacet.Read(reader, h);
                        if (total != null)
                        {
                            restriction.facets.Add(total);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "fractionDigits")
                    {
                        level = 3;
                        XmlSchemaFractionDigitsFacet fraction = XmlSchemaFractionDigitsFacet.Read(reader, h);
                        if (fraction != null)
                        {
                            restriction.facets.Add(fraction);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "length")
                    {
                        level = 3;
                        XmlSchemaLengthFacet length = XmlSchemaLengthFacet.Read(reader, h);
                        if (length != null)
                        {
                            restriction.facets.Add(length);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "minLength")
                    {
                        level = 3;
                        XmlSchemaMinLengthFacet minlen = XmlSchemaMinLengthFacet.Read(reader, h);
                        if (minlen != null)
                        {
                            restriction.facets.Add(minlen);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "maxLength")
                    {
                        level = 3;
                        XmlSchemaMaxLengthFacet maxlen = XmlSchemaMaxLengthFacet.Read(reader, h);
                        if (maxlen != null)
                        {
                            restriction.facets.Add(maxlen);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "enumeration")
                    {
                        level = 3;
                        XmlSchemaEnumerationFacet enumeration = XmlSchemaEnumerationFacet.Read(reader, h);
                        if (enumeration != null)
                        {
                            restriction.facets.Add(enumeration);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "whiteSpace")
                    {
                        level = 3;
                        XmlSchemaWhiteSpaceFacet ws = XmlSchemaWhiteSpaceFacet.Read(reader, h);
                        if (ws != null)
                        {
                            restriction.facets.Add(ws);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "pattern")
                    {
                        level = 3;
                        XmlSchemaPatternFacet pattern = XmlSchemaPatternFacet.Read(reader, h);
                        if (pattern != null)
                        {
                            restriction.facets.Add(pattern);
                        }
                        continue;
                    }
                }
                if (level <= 4)
                {
                    if (reader.LocalName == "attribute")
                    {
                        level = 4;
                        XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader, h);
                        if (attr != null)
                        {
                            restriction.Attributes.Add(attr);
                        }
                        continue;
                    }
                    if (reader.LocalName == "attributeGroup")
                    {
                        level = 4;
                        XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader, h);
                        if (attr != null)
                        {
                            restriction.attributes.Add(attr);
                        }
                        continue;
                    }
                }
                if (level <= 5 && reader.LocalName == "anyAttribute")
                {
                    level = 6;
                    XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader, h);
                    if (anyattr != null)
                    {
                        restriction.AnyAttribute = anyattr;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(restriction);
        }
        private void CompileAttribute(XmlSchemaAttribute xa)
        {
            if (xa.IsProcessing)
            {
                base.SendValidationEvent("Sch_AttributeCircularRef", xa);
            }
            else if (xa.AttDef == null)
            {
                xa.IsProcessing = true;
                SchemaAttDef def = null;
                try
                {
                    if (!xa.RefName.IsEmpty)
                    {
                        XmlSchemaAttribute attribute = (XmlSchemaAttribute) this.schema.Attributes[xa.RefName];
                        if (attribute == null)
                        {
                            throw new XmlSchemaException("Sch_UndeclaredAttribute", xa.RefName.ToString(), xa);
                        }
                        this.CompileAttribute(attribute);
                        if (attribute.AttDef == null)
                        {
                            throw new XmlSchemaException("Sch_RefInvalidAttribute", xa.RefName.ToString(), xa);
                        }
                        def = attribute.AttDef.Clone();
                        if (def.Datatype != null)
                        {
                            if (attribute.FixedValue != null)
                            {
                                if (xa.DefaultValue != null)
                                {
                                    throw new XmlSchemaException("Sch_FixedDefaultInRef", xa.RefName.ToString(), xa);
                                }
                                if (xa.FixedValue != null)
                                {
                                    if (xa.FixedValue != attribute.FixedValue)
                                    {
                                        throw new XmlSchemaException("Sch_FixedInRef", xa.RefName.ToString(), xa);
                                    }
                                }
                                else
                                {
                                    def.Presence = SchemaDeclBase.Use.Fixed;
                                    def.DefaultValueRaw = def.DefaultValueExpanded = attribute.FixedValue;
                                    def.DefaultValueTyped = def.Datatype.ParseValue(def.DefaultValueRaw, base.NameTable, new SchemaNamespaceManager(xa), true);
                                }
                            }
                            else if (((attribute.DefaultValue != null) && (xa.DefaultValue == null)) && (xa.FixedValue == null))
                            {
                                def.Presence = SchemaDeclBase.Use.Default;
                                def.DefaultValueRaw = def.DefaultValueExpanded = attribute.DefaultValue;
                                def.DefaultValueTyped = def.Datatype.ParseValue(def.DefaultValueRaw, base.NameTable, new SchemaNamespaceManager(xa), true);
                            }
                        }
                        xa.SetAttributeType(attribute.AttributeSchemaType);
                    }
                    else
                    {
                        def = new SchemaAttDef(xa.QualifiedName);
                        if (xa.SchemaType != null)
                        {
                            this.CompileSimpleType(xa.SchemaType);
                            xa.SetAttributeType(xa.SchemaType);
                            def.SchemaType = xa.SchemaType;
                            def.Datatype = xa.SchemaType.Datatype;
                        }
                        else if (!xa.SchemaTypeName.IsEmpty)
                        {
                            XmlSchemaSimpleType simpleType = this.GetSimpleType(xa.SchemaTypeName);
                            if (simpleType == null)
                            {
                                throw new XmlSchemaException("Sch_UndeclaredSimpleType", xa.SchemaTypeName.ToString(), xa);
                            }
                            xa.SetAttributeType(simpleType);
                            def.Datatype = simpleType.Datatype;
                            def.SchemaType = simpleType;
                        }
                        else
                        {
                            def.SchemaType = DatatypeImplementation.AnySimpleType;
                            def.Datatype = DatatypeImplementation.AnySimpleType.Datatype;
                            xa.SetAttributeType(DatatypeImplementation.AnySimpleType);
                        }
                    }
                    if (def.Datatype != null)
                    {
                        def.Datatype.VerifySchemaValid(this.schema.Notations, xa);
                    }
                    if ((xa.DefaultValue != null) || (xa.FixedValue != null))
                    {
                        if (xa.DefaultValue != null)
                        {
                            def.Presence = SchemaDeclBase.Use.Default;
                            def.DefaultValueRaw = def.DefaultValueExpanded = xa.DefaultValue;
                        }
                        else
                        {
                            def.Presence = SchemaDeclBase.Use.Fixed;
                            def.DefaultValueRaw = def.DefaultValueExpanded = xa.FixedValue;
                        }
                        if (def.Datatype != null)
                        {
                            def.DefaultValueTyped = def.Datatype.ParseValue(def.DefaultValueRaw, base.NameTable, new SchemaNamespaceManager(xa), true);
                        }
                    }
                    else
                    {
                        switch (xa.Use)
                        {
                            case XmlSchemaUse.None:
                            case XmlSchemaUse.Optional:
                                def.Presence = SchemaDeclBase.Use.Implied;
                                break;

                            case XmlSchemaUse.Required:
                                def.Presence = SchemaDeclBase.Use.Required;
                                break;
                        }
                    }
                    def.SchemaAttribute = xa;
                    xa.AttDef = def;
                }
                catch (XmlSchemaException exception)
                {
                    if (exception.SourceSchemaObject == null)
                    {
                        exception.SetSource(xa);
                    }
                    base.SendValidationEvent(exception);
                    xa.AttDef = SchemaAttDef.Empty;
                }
                finally
                {
                    xa.IsProcessing = false;
                }
            }
        }
예제 #40
0
        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);
        }
예제 #41
0
        public void v5()
        {
            XmlSchemaSet sc = new XmlSchemaSet();
            XmlSchema Schema1 = sc.Add(null, TestData._XsdAuthor);
            CError.Compare(sc.Count, 1, "AddCount");
            CError.Compare(sc.Contains(Schema1), true, "AddContains");
            CError.Compare(sc.IsCompiled, false, "AddIsCompiled");

            sc.Compile();
            CError.Compare(sc.Count, 1, "CompileCount");
            CError.Compare(sc.Contains(Schema1), true, "CompileContains");
            //edit
            XmlSchemaAttribute attributeDog = new XmlSchemaAttribute();

            Schema1.Items.Add(attributeDog);
            attributeDog.Name = "dog";
            attributeDog.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");

            sc.Reprocess(Schema1);
            CError.Compare(sc.Count, 1, "ReprocessCount");
            CError.Compare(sc.Contains(Schema1), true, "ReprocessContains");
            CError.Compare(sc.IsCompiled, false, "ReprocessIsCompiled");

            sc.Compile();
            CError.Compare(sc.Count, 1, "Count Compile");
            CError.Compare(sc.IsCompiled, true, "IsCompiled Compile");
            CError.Compare(Schema1.IsCompiled, true, "IsCompiled on SOM Compile");
            return;
        }
예제 #42
0
        /// <summary>
        /// Schema Component:
        ///			QName, SimpleType, Scope, Default|Fixed, annotation
        /// </summary>
        internal override int Validate(ValidationEventHandler h, XmlSchema schema)
        {
            if (IsValidated(schema.ValidationId))
            {
                return(errorCount);
            }

            // -- Attribute Declaration Schema Component --
            // {name}, {target namespace} -> QualifiedName. Already Compile()d.
            // {type definition} -> attributeType. From SchemaType or SchemaTypeName.
            // {scope} -> ParentIsSchema | isRedefineChild.
            // {value constraint} -> ValidatedFixedValue, ValidatedDefaultValue.
            // {annotation}
            // -- Attribute Use Schema Component --
            // {required}
            // {attribute declaration}
            // {value constraint}

            // First, fill type information for type reference
            if (SchemaType != null)
            {
                SchemaType.Validate(h, schema);
                attributeType = SchemaType;
            }
            else if (SchemaTypeName != null && SchemaTypeName != XmlQualifiedName.Empty)
            {
                // If type is null, then it is missing sub components .
                XmlSchemaType type = schema.FindSchemaType(SchemaTypeName);
                if (type is XmlSchemaComplexType)
                {
                    error(h, "An attribute can't have complexType Content");
                }
                else if (type != null)                          // simple type
                {
                    errorCount   += type.Validate(h, schema);
                    attributeType = type;
                }
                else if (SchemaTypeName == XmlSchemaComplexType.AnyTypeName)
                {
                    attributeType = XmlSchemaComplexType.AnyType;
                }
                else if (XmlSchemaUtil.IsBuiltInDatatypeName(SchemaTypeName))
                {
                    attributeType = XmlSchemaDatatype.FromName(SchemaTypeName);
                    if (attributeType == null)
                    {
                        error(h, "Invalid xml schema namespace datatype was specified.");
                    }
                }
                // otherwise, it might be missing sub components.
                else if (!schema.IsNamespaceAbsent(SchemaTypeName.Namespace))
                {
                    error(h, "Referenced schema type " + SchemaTypeName + " was not found in the corresponding schema.");
                }
            }

            // Then, fill type information for the type references for the referencing attributes
            if (RefName != null && RefName != XmlQualifiedName.Empty)
            {
                referencedAttribute = schema.FindAttribute(RefName);
                // If el is null, then it is missing sub components .
                if (referencedAttribute != null)
                {
                    errorCount += referencedAttribute.Validate(h, schema);
                }
                // otherwise, it might be missing sub components.
                else if (!schema.IsNamespaceAbsent(RefName.Namespace))
                {
                    error(h, "Referenced attribute " + RefName + " was not found in the corresponding schema.");
                }
            }

            if (attributeType == null)
            {
                attributeType = XmlSchemaSimpleType.AnySimpleType;
            }

            // Validate {value constraints}
            if (defaultValue != null || fixedValue != null)
            {
                XmlSchemaDatatype datatype = attributeType as XmlSchemaDatatype;
                if (datatype == null)
                {
                    datatype = ((XmlSchemaSimpleType)attributeType).Datatype;
                }
                if (datatype.TokenizedType == XmlTokenizedType.QName)
                {
                    error(h, "By the defection of the W3C XML Schema specification, it is impossible to supply QName default or fixed values.");
                }
                else
                {
                    try {
                        if (defaultValue != null)
                        {
                            validatedDefaultValue = datatype.Normalize(defaultValue);
                            datatype.ParseValue(validatedDefaultValue, null, null);
                        }
                    } catch (Exception ex) {
                        // FIXME: This is not a good way to handle exception.
                        error(h, "The Attribute's default value is invalid with its type definition.", ex);
                    }
                    try {
                        if (fixedValue != null)
                        {
                            validatedFixedValue      = datatype.Normalize(fixedValue);
                            validatedFixedTypedValue = datatype.ParseValue(validatedFixedValue, null, null);
                        }
                    } catch (Exception ex) {
                        // FIXME: This is not a good way to handle exception.
                        error(h, "The Attribute's fixed value is invalid with its type definition.", ex);
                    }
                }
            }
            if (Use == XmlSchemaUse.None)
            {
                validatedUse = XmlSchemaUse.Optional;
            }
            else
            {
                validatedUse = Use;
            }

#if NET_2_0
            if (attributeType != null)
            {
                attributeSchemaType = attributeType as XmlSchemaSimpleType;
                if (attributeType == XmlSchemaSimpleType.AnySimpleType)
                {
                    attributeSchemaType = XmlSchemaSimpleType.XsAnySimpleType;
                }
                if (attributeSchemaType == null)
                {
                    attributeSchemaType = XmlSchemaType.GetBuiltInSimpleType(SchemaTypeName);
                }
            }
#endif

            ValidationId = schema.ValidationId;
            return(errorCount);
        }
예제 #43
0
        public void v50()
        {
            bWarningCallback = false;
            bErrorCallback = false;
            XmlSchemaSet schemaSet = new XmlSchemaSet();

            XmlSchema schema = new XmlSchema();
            schemaSet.Add(schema);
            schema.TargetNamespace = "http://myns/";

            //type
            XmlSchemaType schemaType = new XmlSchemaComplexType();
            schemaType.Name = "MySimpleType";
            schema.Items.Add(schemaType);
            schemaSet.Reprocess(schema);
            schemaSet.Compile();

            //element
            XmlSchemaElement schemaElement = new XmlSchemaElement();
            schemaElement.Name = "MyElement";
            schema.Items.Add(schemaElement);
            schemaSet.Reprocess(schema);
            schemaSet.Compile();

            //attribute
            XmlSchemaAttribute schemaAttribute = new XmlSchemaAttribute();
            schemaAttribute.Name = "MyAttribute";
            schema.Items.Add(schemaAttribute);
            schemaSet.Reprocess(schema);
            schemaSet.Compile();

            schemaSet.Reprocess(schema);
            schemaSet.Compile();

            schema.Items.Remove(schemaType);//what is the best way to remove it?
            schema.Items.Remove(schemaElement);
            schema.Items.Remove(schemaAttribute);
            schemaSet.Reprocess(schema);
            schemaSet.Compile();

            schemaType = new XmlSchemaComplexType();
            schemaType.Name = "MySimpleType";
            schema.Items.Add(schemaType);
            schema.Items.Add(schemaElement);
            schema.Items.Add(schemaAttribute);
            schemaSet.Reprocess(schema);

            schemaSet.Compile();
            CError.Compare(schemaSet.GlobalElements.Count, 1, "Element count mismatch!");
            CError.Compare(schemaSet.GlobalAttributes.Count, 1, "Attributes count mismatch!");
            CError.Compare(schemaSet.GlobalTypes.Count, 2, "Types count mismatch!");

            return;
        }
예제 #44
0
        //<attribute
        //  default = string
        //  fixed = string
        //  form = (qualified | unqualified)
        //  id = ID
        //  name = NCName
        //  ref = QName
        //  type = QName
        //  use = (optional | prohibited | required) : optional
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, (simpleType?))
        //</attribute>
        internal static XmlSchemaAttribute Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaAttribute attribute = new XmlSchemaAttribute();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
            {
                error(h, "Should not happen :1: XmlSchemaAttribute.Read, name=" + reader.Name, null);
                reader.SkipToEnd();
                return(null);
            }

            attribute.LineNumber   = reader.LineNumber;
            attribute.LinePosition = reader.LinePosition;
            attribute.SourceUri    = reader.BaseURI;

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "default")
                {
                    attribute.defaultValue = reader.Value;
                }
                else if (reader.Name == "fixed")
                {
                    attribute.fixedValue = reader.Value;
                }
                else if (reader.Name == "form")
                {
                    Exception innerex;
                    attribute.form = XmlSchemaUtil.ReadFormAttribute(reader, out innerex);
                    if (innerex != null)
                    {
                        error(h, reader.Value + " is not a valid value for form attribute", innerex);
                    }
                }
                else if (reader.Name == "id")
                {
                    attribute.Id = reader.Value;
                }
                else if (reader.Name == "name")
                {
                    attribute.name = reader.Value;
                }
                else if (reader.Name == "ref")
                {
                    Exception innerex;
                    attribute.refName = XmlSchemaUtil.ReadQNameAttribute(reader, out innerex);
                    if (innerex != null)
                    {
                        error(h, reader.Value + " is not a valid value for ref attribute", innerex);
                    }
                }
                else if (reader.Name == "type")
                {
                    Exception innerex;
                    attribute.schemaTypeName = XmlSchemaUtil.ReadQNameAttribute(reader, out innerex);
                    if (innerex != null)
                    {
                        error(h, reader.Value + " is not a valid value for type attribute", innerex);
                    }
                }
                else if (reader.Name == "use")
                {
                    Exception innerex;
                    attribute.use = XmlSchemaUtil.ReadUseAttribute(reader, out innerex);
                    if (innerex != null)
                    {
                        error(h, reader.Value + " is not a valid value for use attribute", innerex);
                    }
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for attribute", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, attribute);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(attribute);
            }

            //  Content: (annotation?, (simpleType?))
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaAttribute.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)
                    {
                        attribute.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2 && reader.LocalName == "simpleType")
                {
                    level = 3;
                    XmlSchemaSimpleType stype = XmlSchemaSimpleType.Read(reader, h);
                    if (stype != null)
                    {
                        attribute.schemaType = stype;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(attribute);
        }
		/// <summary>
		/// If the attribute value found references another item in the schema
		/// return this instead of the attribute schema object. For example, if the
		/// user can select the attribute value and the code will work out the schema object pointed to by the ref
		/// or type attribute:
		///
		/// xs:element ref="ref-name"
		/// xs:attribute type="type-name"
		/// </summary>
		/// <returns>
		/// The <paramref name="attribute"/> if no schema object was referenced.
		/// </returns>
		XmlSchemaObject GetSchemaObjectReferenced (XmlSchemaCompletionData currentSchemaCompletionData, XmlSchemaElement element, XmlSchemaAttribute attribute)
		{
			XmlSchemaObject schemaObject = null;
			if (IsXmlSchemaNamespace(element)) {
				// Find attribute value.
				//fixme implement
				string attributeValue = "";// XmlParser.GetAttributeValueAtIndex(xml, index);
				if (attributeValue.Length == 0) {
					return attribute;
				}
		
				if (attribute.Name == "ref") {
					schemaObject = FindSchemaObjectReference(attributeValue, currentSchemaCompletionData, element.Name);
				} else if (attribute.Name == "type") {
					schemaObject = FindSchemaObjectType(attributeValue, currentSchemaCompletionData, element.Name);
				}
			}
			
			if (schemaObject != null) {
				return schemaObject;
			}
			return attribute;
		}
예제 #46
0
        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);
                }
            }
        }
 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;
 }
예제 #48
0
        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 PreprocessAttributeContent(XmlSchemaAttribute attribute)
 {
     this.PreprocessAnnotation(attribute);
     if (Ref.Equal(this.currentSchema.TargetNamespace, this.NsXsi))
     {
         base.SendValidationEvent("Sch_TargetNamespaceXsi", attribute);
     }
     if (!attribute.RefName.IsEmpty)
     {
         base.SendValidationEvent("Sch_ForbiddenAttribute", "ref", attribute);
     }
     if ((attribute.DefaultValue != null) && (attribute.FixedValue != null))
     {
         base.SendValidationEvent("Sch_DefaultFixedAttributes", attribute);
     }
     if (((attribute.DefaultValue != null) && (attribute.Use != XmlSchemaUse.Optional)) && (attribute.Use != XmlSchemaUse.None))
     {
         base.SendValidationEvent("Sch_OptionalDefaultAttribute", attribute);
     }
     if (attribute.Name == this.Xmlns)
     {
         base.SendValidationEvent("Sch_XmlNsAttribute", attribute);
     }
     if (attribute.SchemaType != null)
     {
         this.SetParent(attribute.SchemaType, attribute);
         if (!attribute.SchemaTypeName.IsEmpty)
         {
             base.SendValidationEvent("Sch_TypeMutualExclusive", attribute);
         }
         this.PreprocessSimpleType(attribute.SchemaType, true);
     }
     if (!attribute.SchemaTypeName.IsEmpty)
     {
         this.ValidateQNameAttribute(attribute, "type", attribute.SchemaTypeName);
     }
 }
예제 #50
0
        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);
        }