Validate() private method

private Validate ( XmlReader reader, XmlResolver resolver, XmlSchemaSet schemaSet, ValidationEventHandler valEventHandler ) : XmlReader
reader XmlReader
resolver XmlResolver
schemaSet XmlSchemaSet
valEventHandler ValidationEventHandler
return XmlReader
        internal override int Validate(ValidationEventHandler h, XmlSchema schema)
        {
            if (IsValidated(schema.ValidationId))
            {
                return(errorCount);
            }

            if (baseType != null)
            {
                baseType.Validate(h, schema);
                actualBaseSchemaType = baseType;
            }
            else if (baseTypeName != XmlQualifiedName.Empty)
            {
                XmlSchemaType st = schema.FindSchemaType(baseTypeName);
                if (st != null)
                {
                    st.Validate(h, schema);
                    actualBaseSchemaType = st;
                }
                else if (baseTypeName == XmlSchemaComplexType.AnyTypeName)
                {
                    actualBaseSchemaType = XmlSchemaComplexType.AnyType;
                }
                else if (XmlSchemaUtil.IsBuiltInDatatypeName(baseTypeName))
                {
                    actualBaseSchemaType = XmlSchemaDatatype.FromName(baseTypeName);
                    if (actualBaseSchemaType == null)
                    {
                        error(h, "Invalid schema datatype name is specified.");
                    }
                }
                // otherwise, it might be missing sub components.
                else if (!schema.IsNamespaceAbsent(baseTypeName.Namespace))
                {
                    error(h, "Referenced base schema type " + baseTypeName + " was not found in the corresponding schema.");
                }
            }

            ValidationId = schema.ValidationId;
            return(errorCount);
        }
 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
 {
     if (base.IsValidated(schema.ValidationId))
     {
         return(this.errorCount);
     }
     if (this.baseType != null)
     {
         this.baseType.Validate(h, schema);
         this.actualBaseSchemaType = this.baseType;
     }
     else if (this.baseTypeName != XmlQualifiedName.Empty)
     {
         XmlSchemaType xmlSchemaType = schema.FindSchemaType(this.baseTypeName);
         if (xmlSchemaType != null)
         {
             xmlSchemaType.Validate(h, schema);
             this.actualBaseSchemaType = xmlSchemaType;
         }
         else if (this.baseTypeName == XmlSchemaComplexType.AnyTypeName)
         {
             this.actualBaseSchemaType = XmlSchemaComplexType.AnyType;
         }
         else if (XmlSchemaUtil.IsBuiltInDatatypeName(this.baseTypeName))
         {
             this.actualBaseSchemaType = XmlSchemaDatatype.FromName(this.baseTypeName);
             if (this.actualBaseSchemaType == null)
             {
                 base.error(h, "Invalid schema datatype name is specified.");
             }
         }
         else if (!schema.IsNamespaceAbsent(this.baseTypeName.Namespace))
         {
             base.error(h, "Referenced base schema type " + this.baseTypeName + " was not found in the corresponding schema.");
         }
     }
     this.ValidationId = schema.ValidationId;
     return(this.errorCount);
 }
Esempio n. 3
0
        internal override int Validate(ValidationEventHandler h, XmlSchema schema)
        {
            if (IsValidated(schema.ValidationId))
            {
                return(errorCount);
            }

            ArrayList al = new ArrayList();

            // Validate MemberTypes
            if (MemberTypes != null)
            {
                foreach (XmlQualifiedName memberTypeName in MemberTypes)
                {
                    object        type   = null;
                    XmlSchemaType xstype = schema.FindSchemaType(memberTypeName) as XmlSchemaSimpleType;
                    if (xstype != null)
                    {
                        errorCount += xstype.Validate(h, schema);
                        type        = xstype;
                    }
                    else if (memberTypeName == XmlSchemaComplexType.AnyTypeName)
                    {
                        type = XmlSchemaSimpleType.AnySimpleType;
                    }
                    else if (memberTypeName.Namespace == XmlSchema.Namespace ||
                             memberTypeName.Namespace == XmlSchema.XdtNamespace)
                    {
                        type = XmlSchemaDatatype.FromName(memberTypeName);
                        if (type == null)
                        {
                            error(h, "Invalid schema type name was specified: " + memberTypeName);
                        }
                    }
                    // otherwise, it might be missing sub components.
                    else if (!schema.IsNamespaceAbsent(memberTypeName.Namespace))
                    {
                        error(h, "Referenced base schema type " + memberTypeName + " was not found in the corresponding schema.");
                    }

                    al.Add(type);
                }
            }
            if (BaseTypes != null)
            {
                foreach (XmlSchemaSimpleType st in BaseTypes)
                {
                    st.Validate(h, schema);
                    al.Add(st);
                }
            }
            this.validatedTypes = al.ToArray();

            if (validatedTypes != null)
            {
                validatedSchemaTypes = new XmlSchemaSimpleType [validatedTypes.Length];
                for (int i = 0; i < validatedTypes.Length; i++)
                {
                    object t = validatedTypes [i];
                    XmlSchemaSimpleType st = t as XmlSchemaSimpleType;
                    if (st == null && t != null)
                    {
                        st = XmlSchemaType.GetBuiltInSimpleType(((XmlSchemaDatatype)t).TypeCode);
                    }
                    validatedSchemaTypes [i] = st;
                }
            }

            ValidationId = schema.ValidationId;
            return(errorCount);
        }
 private XmlReader GetValidatingReader(XmlReader reader, XmlSchemaSet schemas, ValidationEventHandler validationEvent, XmlSchemaType schemaType, XmlSchemaElement schemaElement, XmlSchemaAttribute schemaAttribute)
 {
     if (schemaAttribute != null)
     {
         return schemaAttribute.Validate(reader, null, schemas, validationEvent);
     }
     if (schemaElement != null)
     {
         return schemaElement.Validate(reader, null, schemas, validationEvent);
     }
     if (schemaType != null)
     {
         return schemaType.Validate(reader, null, schemas, validationEvent);
     }
     XmlReaderSettings settings = new XmlReaderSettings {
         ConformanceLevel = ConformanceLevel.Auto,
         ValidationType = ValidationType.Schema,
         Schemas = schemas
     };
     settings.ValidationEventHandler += validationEvent;
     return XmlReader.Create(reader, settings);
 }
 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
 {
     if (base.IsValidated(schema.ValidationId))
     {
         return(this.errorCount);
     }
     if (this.SchemaType != null)
     {
         this.SchemaType.Validate(h, schema);
         this.attributeType = this.SchemaType;
     }
     else if (this.SchemaTypeName != null && this.SchemaTypeName != XmlQualifiedName.Empty)
     {
         XmlSchemaType xmlSchemaType = schema.FindSchemaType(this.SchemaTypeName);
         if (xmlSchemaType is XmlSchemaComplexType)
         {
             base.error(h, "An attribute can't have complexType Content");
         }
         else if (xmlSchemaType != null)
         {
             this.errorCount   += xmlSchemaType.Validate(h, schema);
             this.attributeType = xmlSchemaType;
         }
         else if (this.SchemaTypeName == XmlSchemaComplexType.AnyTypeName)
         {
             this.attributeType = XmlSchemaComplexType.AnyType;
         }
         else if (XmlSchemaUtil.IsBuiltInDatatypeName(this.SchemaTypeName))
         {
             this.attributeType = XmlSchemaDatatype.FromName(this.SchemaTypeName);
             if (this.attributeType == null)
             {
                 base.error(h, "Invalid xml schema namespace datatype was specified.");
             }
         }
         else if (!schema.IsNamespaceAbsent(this.SchemaTypeName.Namespace))
         {
             base.error(h, "Referenced schema type " + this.SchemaTypeName + " was not found in the corresponding schema.");
         }
     }
     if (this.RefName != null && this.RefName != XmlQualifiedName.Empty)
     {
         this.referencedAttribute = schema.FindAttribute(this.RefName);
         if (this.referencedAttribute != null)
         {
             this.errorCount += this.referencedAttribute.Validate(h, schema);
         }
         else if (!schema.IsNamespaceAbsent(this.RefName.Namespace))
         {
             base.error(h, "Referenced attribute " + this.RefName + " was not found in the corresponding schema.");
         }
     }
     if (this.attributeType == null)
     {
         this.attributeType = XmlSchemaSimpleType.AnySimpleType;
     }
     if (this.defaultValue != null || this.fixedValue != null)
     {
         XmlSchemaDatatype xmlSchemaDatatype = this.attributeType as XmlSchemaDatatype;
         if (xmlSchemaDatatype == null)
         {
             xmlSchemaDatatype = ((XmlSchemaSimpleType)this.attributeType).Datatype;
         }
         if (xmlSchemaDatatype.TokenizedType == XmlTokenizedType.QName)
         {
             base.error(h, "By the defection of the W3C XML Schema specification, it is impossible to supply QName default or fixed values.");
         }
         else
         {
             try
             {
                 if (this.defaultValue != null)
                 {
                     this.validatedDefaultValue = xmlSchemaDatatype.Normalize(this.defaultValue);
                     xmlSchemaDatatype.ParseValue(this.validatedDefaultValue, null, null);
                 }
             }
             catch (Exception innerException)
             {
                 XmlSchemaObject.error(h, "The Attribute's default value is invalid with its type definition.", innerException);
             }
             try
             {
                 if (this.fixedValue != null)
                 {
                     this.validatedFixedValue      = xmlSchemaDatatype.Normalize(this.fixedValue);
                     this.validatedFixedTypedValue = xmlSchemaDatatype.ParseValue(this.validatedFixedValue, null, null);
                 }
             }
             catch (Exception innerException2)
             {
                 XmlSchemaObject.error(h, "The Attribute's fixed value is invalid with its type definition.", innerException2);
             }
         }
     }
     if (this.Use == XmlSchemaUse.None)
     {
         this.validatedUse = XmlSchemaUse.Optional;
     }
     else
     {
         this.validatedUse = this.Use;
     }
     if (this.attributeType != null)
     {
         this.attributeSchemaType = (this.attributeType as XmlSchemaSimpleType);
         if (this.attributeType == XmlSchemaSimpleType.AnySimpleType)
         {
             this.attributeSchemaType = XmlSchemaSimpleType.XsAnySimpleType;
         }
         if (this.attributeSchemaType == null)
         {
             this.attributeSchemaType = XmlSchemaType.GetBuiltInSimpleType(this.SchemaTypeName);
         }
     }
     this.ValidationId = schema.ValidationId;
     return(this.errorCount);
 }
Esempio n. 6
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);
        }
Esempio n. 7
0
 private XmlReader GetValidatingReader( XmlReader reader, XmlSchemaSet schemas, ValidationEventHandler validationEvent, XmlSchemaType schemaType, XmlSchemaElement schemaElement, XmlSchemaAttribute schemaAttribute ) {
     if (schemaAttribute != null) {
         return schemaAttribute.Validate(reader, null, schemas, validationEvent);
     }
     else if (schemaElement != null) {
         return schemaElement.Validate(reader, null, schemas, validationEvent);
     }
     else if (schemaType != null) {
         return schemaType.Validate(reader, null, schemas, validationEvent);
     }
     Debug.Assert( schemas != null, "schemas != null" );
     XmlReaderSettings readerSettings = new XmlReaderSettings();
     readerSettings.ConformanceLevel = ConformanceLevel.Auto;
     readerSettings.ValidationType = ValidationType.Schema;
     readerSettings.Schemas = schemas;
     readerSettings.ValidationEventHandler += validationEvent;
     return XmlReader.Create( reader, readerSettings );
 }
        internal override int Validate(ValidationEventHandler h, XmlSchema schema)
        {
            if (base.IsValidated(schema.ValidationId))
            {
                return(this.errorCount);
            }
            ArrayList arrayList = new ArrayList();

            if (this.MemberTypes != null)
            {
                foreach (XmlQualifiedName xmlQualifiedName in this.MemberTypes)
                {
                    object        obj           = null;
                    XmlSchemaType xmlSchemaType = schema.FindSchemaType(xmlQualifiedName) as XmlSchemaSimpleType;
                    if (xmlSchemaType != null)
                    {
                        this.errorCount += xmlSchemaType.Validate(h, schema);
                        obj              = xmlSchemaType;
                    }
                    else if (xmlQualifiedName == XmlSchemaComplexType.AnyTypeName)
                    {
                        obj = XmlSchemaSimpleType.AnySimpleType;
                    }
                    else if (xmlQualifiedName.Namespace == "http://www.w3.org/2001/XMLSchema" || xmlQualifiedName.Namespace == "http://www.w3.org/2003/11/xpath-datatypes")
                    {
                        obj = XmlSchemaDatatype.FromName(xmlQualifiedName);
                        if (obj == null)
                        {
                            base.error(h, "Invalid schema type name was specified: " + xmlQualifiedName);
                        }
                    }
                    else if (!schema.IsNamespaceAbsent(xmlQualifiedName.Namespace))
                    {
                        base.error(h, "Referenced base schema type " + xmlQualifiedName + " was not found in the corresponding schema.");
                    }
                    arrayList.Add(obj);
                }
            }
            if (this.BaseTypes != null)
            {
                foreach (XmlSchemaObject xmlSchemaObject in this.BaseTypes)
                {
                    XmlSchemaSimpleType xmlSchemaSimpleType = (XmlSchemaSimpleType)xmlSchemaObject;
                    xmlSchemaSimpleType.Validate(h, schema);
                    arrayList.Add(xmlSchemaSimpleType);
                }
            }
            this.validatedTypes = arrayList.ToArray();
            if (this.validatedTypes != null)
            {
                this.validatedSchemaTypes = new XmlSchemaSimpleType[this.validatedTypes.Length];
                for (int j = 0; j < this.validatedTypes.Length; j++)
                {
                    object obj2 = this.validatedTypes[j];
                    XmlSchemaSimpleType xmlSchemaSimpleType2 = obj2 as XmlSchemaSimpleType;
                    if (xmlSchemaSimpleType2 == null && obj2 != null)
                    {
                        xmlSchemaSimpleType2 = XmlSchemaType.GetBuiltInSimpleType(((XmlSchemaDatatype)obj2).TypeCode);
                    }
                    this.validatedSchemaTypes[j] = xmlSchemaSimpleType2;
                }
            }
            this.ValidationId = schema.ValidationId;
            return(this.errorCount);
        }