GetBuiltInSimpleType() публичный статический Метод

public static GetBuiltInSimpleType ( XmlQualifiedName qualifiedName ) : XmlSchemaSimpleType
qualifiedName XmlQualifiedName
Результат XmlSchemaSimpleType
Пример #1
0
        private QName InferMergedType(string value, QName typeName)
        {
            // examine value against specified type and
            // if unacceptable, then return a relaxed type.

            SimpleType st = XmlSchemaType.GetBuiltInSimpleType(
                typeName);

            if (st == null)             // non-primitive type => see above.
            {
                return(QNameString);
            }
            do
            {
                try {
                    st.Datatype.ParseValue(value,
                                           source.NameTable,
                                           source as IXmlNamespaceResolver);
                    return(typeName);
                } catch {
                    st       = st.BaseXmlSchemaType as XmlSchemaSimpleType;
                    typeName = st != null ? st.QualifiedName : QName.Empty;
                }
            } while (typeName != QName.Empty);
            return(QNameString);
        }
Пример #2
0
 internal static XmlSchemaType GetBuiltInType(XmlTypeCode typecode)
 {
     if (typecode == XmlTypeCode.Item)
     {
         return(XmlSchemaComplexType.AnyType);
     }
     return(XmlSchemaType.GetBuiltInSimpleType(typecode));
 }
Пример #3
0
        internal static XmlSchemaType GetBuiltInType(XmlQualifiedName qualifiedName)
        {
            XmlSchemaType xmlSchemaType = XmlSchemaType.GetBuiltInSimpleType(qualifiedName);

            if (xmlSchemaType == null)
            {
                xmlSchemaType = XmlSchemaType.GetBuiltInComplexType(qualifiedName);
            }
            return(xmlSchemaType);
        }
Пример #4
0
        private static XmlSchemaSimpleType BuildSchemaType(string name, string baseName, bool xdt, bool baseXdt)
        {
            string ns              = xdt ? "http://www.w3.org/2003/11/xpath-datatypes" : XmlSchema.Namespace;
            string ns2             = baseXdt ? "http://www.w3.org/2003/11/xpath-datatypes" : XmlSchema.Namespace;
            XmlSchemaSimpleType st = new XmlSchemaSimpleType();

            st.QNameInternal = new XmlQualifiedName(name, ns);
            if (baseName != null)
            {
                st.BaseXmlSchemaTypeInternal = XmlSchemaType.GetBuiltInSimpleType(new XmlQualifiedName(baseName, ns2));
            }
            st.DatatypeInternal = XmlSchemaDatatype.FromName(st.QualifiedName);
            return(st);
        }
Пример #5
0
        private SimpleType MakeBaseTypeAsEmptiable(SimpleType st)
        {
            switch (st.QualifiedName.Namespace)
            {
            case XmlSchema.Namespace:
            case XdtNamespace:
                // If a primitive type
                return(XmlSchemaType.GetBuiltInSimpleType(
                           XmlTypeCode.String));
            }
            SimpleTypeRst str = st.Content as SimpleTypeRst;

            if (str != null)
            {
                ArrayList al = null;
                foreach (SchemaFacet f in str.Facets)
                {
                    if (f is LengthFacet ||
                        f is MinLengthFacet)
                    {
                        if (al == null)
                        {
                            al = new ArrayList();
                        }
                        al.Add(f);
                    }
                }
                foreach (SchemaFacet f in al)
                {
                    str.Facets.Remove(f);
                }
                if (str.BaseType != null)
                {
                    str.BaseType =
                        MakeBaseTypeAsEmptiable(st);
                }
                else
                {
                    // It might have a reference to an
                    // external simple type, but there is
                    // no assurance that any of those
                    // external types allow an empty
                    // string. So just set base type as
                    // xs:string.
                    str.BaseTypeName = QNameString;
                }
            }             // union/list can have empty string value.

            return(st);
        }
        private static XmlSchemaSimpleType BuildSchemaType(string name, string baseName, bool xdt, bool baseXdt)
        {
            string ns  = (!xdt) ? "http://www.w3.org/2001/XMLSchema" : "http://www.w3.org/2003/11/xpath-datatypes";
            string ns2 = (!baseXdt) ? "http://www.w3.org/2001/XMLSchema" : "http://www.w3.org/2003/11/xpath-datatypes";
            XmlSchemaSimpleType xmlSchemaSimpleType = new XmlSchemaSimpleType();

            xmlSchemaSimpleType.QNameInternal = new XmlQualifiedName(name, ns);
            if (baseName != null)
            {
                xmlSchemaSimpleType.BaseXmlSchemaTypeInternal = XmlSchemaType.GetBuiltInSimpleType(new XmlQualifiedName(baseName, ns2));
            }
            xmlSchemaSimpleType.DatatypeInternal = XmlSchemaDatatype.FromName(xmlSchemaSimpleType.QualifiedName);
            return(xmlSchemaSimpleType);
        }
Пример #7
0
        internal override int Validate(ValidationEventHandler h, XmlSchema schema)
        {
            if (IsValidated(schema.ValidationId))
            {
                return(errorCount);
            }

            // ListItemType
            XmlSchemaSimpleType type = itemType;

            if (type == null)
            {
                type = schema.FindSchemaType(itemTypeName) as XmlSchemaSimpleType;
            }
            if (type != null)
            {
                errorCount           += type.Validate(h, schema);
                validatedListItemType = type;
            }
            else if (itemTypeName == XmlSchemaComplexType.AnyTypeName)
            {
                validatedListItemType = XmlSchemaSimpleType.AnySimpleType;
            }
            else if (XmlSchemaUtil.IsBuiltInDatatypeName(itemTypeName))
            {
                validatedListItemType = XmlSchemaDatatype.FromName(itemTypeName);
                if (validatedListItemType == null)
                {
                    error(h, "Invalid schema type name was specified: " + itemTypeName);
                }
            }
            // otherwise, it might be missing sub components.
            else if (!schema.IsNamespaceAbsent(itemTypeName.Namespace))
            {
                error(h, "Referenced base list item schema type " + itemTypeName + " was not found.");
            }

#if NET_2_0
            XmlSchemaSimpleType st = validatedListItemType as XmlSchemaSimpleType;
            if (st == null && validatedListItemType != null)
            {
                st = XmlSchemaType.GetBuiltInSimpleType(((XmlSchemaDatatype)validatedListItemType).TypeCode);
            }
            validatedListItemSchemaType = st;
#endif

            ValidationId = schema.ValidationId;
            return(errorCount);
        }
Пример #8
0
        protected XmlBaseConverter(XmlSchemaType schemaType)
        {
            XmlSchemaDatatype datatype = schemaType.Datatype;

            while ((schemaType != null) && !(schemaType is XmlSchemaSimpleType))
            {
                schemaType = schemaType.BaseXmlSchemaType;
            }
            if (schemaType == null)
            {
                schemaType = XmlSchemaType.GetBuiltInSimpleType(datatype.TypeCode);
            }
            this.schemaType     = schemaType;
            this.typeCode       = schemaType.TypeCode;
            this.clrTypeDefault = schemaType.Datatype.ValueType;
        }
Пример #9
0
 public override object ChangeType(double value, Type destinationType)
 {
     if (destinationType == null)
     {
         throw new ArgumentNullException("destinationType");
     }
     if (destinationType == XmlBaseConverter.ObjectType)
     {
         destinationType = base.DefaultClrType;
     }
     if (destinationType == XmlBaseConverter.XmlAtomicValueType)
     {
         return(new XmlAtomicValue(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Double), value));
     }
     return(this.ChangeTypeWildcardSource(value, destinationType, null));
 }
Пример #10
0
 internal static XmlSchemaSimpleType GetBuiltInSimpleType(XmlSchemaDatatype type)
 {
     if (type is XsdEntities)
     {
         return(XmlSchemaSimpleType.XsEntities);
     }
     if (type is XsdNMTokens)
     {
         return(XmlSchemaSimpleType.XsNMTokens);
     }
     if (type is XsdIDRefs)
     {
         return(XmlSchemaSimpleType.XsIDRefs);
     }
     return(XmlSchemaType.GetBuiltInSimpleType(type.TypeCode));
 }
Пример #11
0
        internal override int Validate(ValidationEventHandler h, XmlSchema schema)
        {
            if (base.IsValidated(schema.ValidationId))
            {
                return(this.errorCount);
            }
            XmlSchemaSimpleType xmlSchemaSimpleType = this.itemType;

            if (xmlSchemaSimpleType == null)
            {
                xmlSchemaSimpleType = (schema.FindSchemaType(this.itemTypeName) as XmlSchemaSimpleType);
            }
            if (xmlSchemaSimpleType != null)
            {
                this.errorCount           += xmlSchemaSimpleType.Validate(h, schema);
                this.validatedListItemType = xmlSchemaSimpleType;
            }
            else if (this.itemTypeName == XmlSchemaComplexType.AnyTypeName)
            {
                this.validatedListItemType = XmlSchemaSimpleType.AnySimpleType;
            }
            else if (XmlSchemaUtil.IsBuiltInDatatypeName(this.itemTypeName))
            {
                this.validatedListItemType = XmlSchemaDatatype.FromName(this.itemTypeName);
                if (this.validatedListItemType == null)
                {
                    base.error(h, "Invalid schema type name was specified: " + this.itemTypeName);
                }
            }
            else if (!schema.IsNamespaceAbsent(this.itemTypeName.Namespace))
            {
                base.error(h, "Referenced base list item schema type " + this.itemTypeName + " was not found.");
            }
            XmlSchemaSimpleType xmlSchemaSimpleType2 = this.validatedListItemType as XmlSchemaSimpleType;

            if (xmlSchemaSimpleType2 == null && this.validatedListItemType != null)
            {
                xmlSchemaSimpleType2 = XmlSchemaType.GetBuiltInSimpleType(((XmlSchemaDatatype)this.validatedListItemType).TypeCode);
            }
            this.validatedListItemSchemaType = xmlSchemaSimpleType2;
            this.ValidationId = schema.ValidationId;
            return(this.errorCount);
        }
Пример #12
0
        private ComplexType ToComplexType(Element el)
        {
            QName         name = el.SchemaTypeName;
            XmlSchemaType type = el.SchemaType;

            // 1. element type is complex.
            ComplexType ct = type as ComplexType;

            if (ct != null)
            {
                return(ct);
            }

            // 2. reference to global complexType.
            XmlSchemaType globalType = schemas.GlobalTypes [name]
                                       as XmlSchemaType;

            ct = globalType as ComplexType;
            if (ct != null)
            {
                return(ct);
            }

            ct                = new ComplexType();
            el.SchemaType     = ct;
            el.SchemaTypeName = QName.Empty;

            // 3. base type name is xs:anyType or no specification.
            // <xs:complexType />
            if (name == QNameAnyType)
            {
                return(ct);
            }
            else if (type == null && name == QName.Empty)
            {
                return(ct);
            }

            SimpleModel sc = new SimpleModel();

            ct.ContentModel = sc;

            // 4. type is simpleType
            //    -> extension of existing simple type.
            SimpleType st = type as SimpleType;

            if (st != null)
            {
                SimpleRst scr = new SimpleRst();
                scr.BaseType = st;
                sc.Content   = scr;
                return(ct);
            }

            SimpleExt sce = new SimpleExt();

            sc.Content = sce;

            // 5. type name points to primitive type
            //    -> simple extension of a primitive type
            st = XmlSchemaType.GetBuiltInSimpleType(name);
            if (st != null)
            {
                sce.BaseTypeName = name;
                return(ct);
            }

            // 6. type name points to global simpleType.
            st = globalType as SimpleType;
            if (st != null)
            {
                sce.BaseTypeName = name;
                return(ct);
            }

            throw Error(el, "Unexpected schema component that contains simpleTypeName that could not be resolved.");
        }
Пример #13
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);
        }
Пример #14
0
        public override object ChangeType(object value, Type destinationType, IXmlNamespaceResolver nsResolver)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            if (destinationType == null)
            {
                throw new ArgumentNullException("destinationType");
            }
            Type derivedType = value.GetType();

            if (destinationType == XmlBaseConverter.ObjectType)
            {
                destinationType = base.DefaultClrType;
            }
            if ((destinationType == XmlBaseConverter.BooleanType) && (derivedType == XmlBaseConverter.XmlAtomicValueType))
            {
                return(((XmlAtomicValue)value).ValueAsBoolean);
            }
            if ((destinationType == XmlBaseConverter.DateTimeType) && (derivedType == XmlBaseConverter.XmlAtomicValueType))
            {
                return(((XmlAtomicValue)value).ValueAsDateTime);
            }
            if ((destinationType == XmlBaseConverter.DateTimeOffsetType) && (derivedType == XmlBaseConverter.XmlAtomicValueType))
            {
                return(((XmlAtomicValue)value).ValueAs(XmlBaseConverter.DateTimeOffsetType));
            }
            if ((destinationType == XmlBaseConverter.DecimalType) && (derivedType == XmlBaseConverter.XmlAtomicValueType))
            {
                return((decimal)((XmlAtomicValue)value).ValueAs(XmlBaseConverter.DecimalType));
            }
            if ((destinationType == XmlBaseConverter.DoubleType) && (derivedType == XmlBaseConverter.XmlAtomicValueType))
            {
                return(((XmlAtomicValue)value).ValueAsDouble);
            }
            if ((destinationType == XmlBaseConverter.Int32Type) && (derivedType == XmlBaseConverter.XmlAtomicValueType))
            {
                return(((XmlAtomicValue)value).ValueAsInt);
            }
            if ((destinationType == XmlBaseConverter.Int64Type) && (derivedType == XmlBaseConverter.XmlAtomicValueType))
            {
                return(((XmlAtomicValue)value).ValueAsLong);
            }
            if ((destinationType == XmlBaseConverter.SingleType) && (derivedType == XmlBaseConverter.XmlAtomicValueType))
            {
                return((float)((XmlAtomicValue)value).ValueAs(XmlBaseConverter.SingleType));
            }
            if (destinationType == XmlBaseConverter.XmlAtomicValueType)
            {
                if (derivedType == XmlBaseConverter.XmlAtomicValueType)
                {
                    return((XmlAtomicValue)value);
                }
                if (derivedType == XmlBaseConverter.BooleanType)
                {
                    return(new XmlAtomicValue(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Boolean), (bool)value));
                }
                if (derivedType == XmlBaseConverter.ByteType)
                {
                    return(new XmlAtomicValue(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.UnsignedByte), value));
                }
                if (derivedType == XmlBaseConverter.ByteArrayType)
                {
                    return(new XmlAtomicValue(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Base64Binary), value));
                }
                if (derivedType == XmlBaseConverter.DateTimeType)
                {
                    return(new XmlAtomicValue(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.DateTime), (DateTime)value));
                }
                if (derivedType == XmlBaseConverter.DateTimeOffsetType)
                {
                    return(new XmlAtomicValue(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.DateTime), (DateTimeOffset)value));
                }
                if (derivedType == XmlBaseConverter.DecimalType)
                {
                    return(new XmlAtomicValue(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Decimal), value));
                }
                if (derivedType == XmlBaseConverter.DoubleType)
                {
                    return(new XmlAtomicValue(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Double), (double)value));
                }
                if (derivedType == XmlBaseConverter.Int16Type)
                {
                    return(new XmlAtomicValue(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Short), value));
                }
                if (derivedType == XmlBaseConverter.Int32Type)
                {
                    return(new XmlAtomicValue(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Int), (int)value));
                }
                if (derivedType == XmlBaseConverter.Int64Type)
                {
                    return(new XmlAtomicValue(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Long), (long)value));
                }
                if (derivedType == XmlBaseConverter.SByteType)
                {
                    return(new XmlAtomicValue(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Byte), value));
                }
                if (derivedType == XmlBaseConverter.SingleType)
                {
                    return(new XmlAtomicValue(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Float), value));
                }
                if (derivedType == XmlBaseConverter.StringType)
                {
                    return(new XmlAtomicValue(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String), (string)value));
                }
                if (derivedType == XmlBaseConverter.TimeSpanType)
                {
                    return(new XmlAtomicValue(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Duration), value));
                }
                if (derivedType == XmlBaseConverter.UInt16Type)
                {
                    return(new XmlAtomicValue(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.UnsignedShort), value));
                }
                if (derivedType == XmlBaseConverter.UInt32Type)
                {
                    return(new XmlAtomicValue(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.UnsignedInt), value));
                }
                if (derivedType == XmlBaseConverter.UInt64Type)
                {
                    return(new XmlAtomicValue(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.UnsignedLong), value));
                }
                if (XmlBaseConverter.IsDerivedFrom(derivedType, XmlBaseConverter.UriType))
                {
                    return(new XmlAtomicValue(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.AnyUri), value));
                }
                if (XmlBaseConverter.IsDerivedFrom(derivedType, XmlBaseConverter.XmlQualifiedNameType))
                {
                    return(new XmlAtomicValue(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.QName), value, nsResolver));
                }
            }
            if (destinationType == XmlBaseConverter.XPathItemType)
            {
                if (derivedType == XmlBaseConverter.XmlAtomicValueType)
                {
                    return((XmlAtomicValue)value);
                }
                if (XmlBaseConverter.IsDerivedFrom(derivedType, XmlBaseConverter.XPathNavigatorType))
                {
                    return((XPathNavigator)value);
                }
            }
            if ((destinationType == XmlBaseConverter.XPathNavigatorType) && XmlBaseConverter.IsDerivedFrom(derivedType, XmlBaseConverter.XPathNavigatorType))
            {
                return(this.ToNavigator((XPathNavigator)value));
            }
            if (destinationType == XmlBaseConverter.XPathItemType)
            {
                return((XPathItem)this.ChangeType(value, XmlBaseConverter.XmlAtomicValueType, nsResolver));
            }
            if (derivedType == XmlBaseConverter.XmlAtomicValueType)
            {
                return(((XmlAtomicValue)value).ValueAs(destinationType, nsResolver));
            }
            return(this.ChangeListType(value, destinationType, nsResolver));
        }
 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);
 }
Пример #16
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);
        }
        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);
        }