internal override Exception CheckValueFacets(double value, XmlSchemaDatatype datatype)
 {
     RestrictionFacets restriction = datatype.Restriction;
     RestrictionFlags flags = (restriction != null) ? restriction.Flags : ((RestrictionFlags) 0);
     XmlValueConverter valueConverter = datatype.ValueConverter;
     if (((flags & RestrictionFlags.MaxInclusive) != 0) && (value > valueConverter.ToDouble(restriction.MaxInclusive)))
     {
         return new XmlSchemaException("Sch_MaxInclusiveConstraintFailed", string.Empty);
     }
     if (((flags & RestrictionFlags.MaxExclusive) != 0) && (value >= valueConverter.ToDouble(restriction.MaxExclusive)))
     {
         return new XmlSchemaException("Sch_MaxExclusiveConstraintFailed", string.Empty);
     }
     if (((flags & RestrictionFlags.MinInclusive) != 0) && (value < valueConverter.ToDouble(restriction.MinInclusive)))
     {
         return new XmlSchemaException("Sch_MinInclusiveConstraintFailed", string.Empty);
     }
     if (((flags & RestrictionFlags.MinExclusive) != 0) && (value <= valueConverter.ToDouble(restriction.MinExclusive)))
     {
         return new XmlSchemaException("Sch_MinExclusiveConstraintFailed", string.Empty);
     }
     if (((flags & RestrictionFlags.Enumeration) != 0) && !this.MatchEnumeration(value, restriction.Enumeration, valueConverter))
     {
         return new XmlSchemaException("Sch_EnumerationConstraintFailed", string.Empty);
     }
     return null;
 }
 internal override Exception CheckValueFacets(TimeSpan value, XmlSchemaDatatype datatype)
 {
     RestrictionFacets restriction = datatype.Restriction;
     RestrictionFlags flags = (restriction != null) ? restriction.Flags : ((RestrictionFlags) 0);
     if (((flags & RestrictionFlags.MaxInclusive) != 0) && (TimeSpan.Compare(value, (TimeSpan) restriction.MaxInclusive) > 0))
     {
         return new XmlSchemaException("Sch_MaxInclusiveConstraintFailed", string.Empty);
     }
     if (((flags & RestrictionFlags.MaxExclusive) != 0) && (TimeSpan.Compare(value, (TimeSpan) restriction.MaxExclusive) >= 0))
     {
         return new XmlSchemaException("Sch_MaxExclusiveConstraintFailed", string.Empty);
     }
     if (((flags & RestrictionFlags.MinInclusive) != 0) && (TimeSpan.Compare(value, (TimeSpan) restriction.MinInclusive) < 0))
     {
         return new XmlSchemaException("Sch_MinInclusiveConstraintFailed", string.Empty);
     }
     if (((flags & RestrictionFlags.MinExclusive) != 0) && (TimeSpan.Compare(value, (TimeSpan) restriction.MinExclusive) <= 0))
     {
         return new XmlSchemaException("Sch_MinExclusiveConstraintFailed", string.Empty);
     }
     if (((flags & RestrictionFlags.Enumeration) != 0) && !this.MatchEnumeration(value, restriction.Enumeration))
     {
         return new XmlSchemaException("Sch_EnumerationConstraintFailed", string.Empty);
     }
     return null;
 }
 internal override Exception CheckValueFacets(byte[] value, XmlSchemaDatatype datatype)
 {
     RestrictionFacets restriction = datatype.Restriction;
     int length = value.Length;
     RestrictionFlags flags = (restriction != null) ? restriction.Flags : ((RestrictionFlags) 0);
     if (flags != 0)
     {
         if (((flags & RestrictionFlags.Length) != 0) && (restriction.Length != length))
         {
             return new XmlSchemaException("Sch_LengthConstraintFailed", string.Empty);
         }
         if (((flags & RestrictionFlags.MinLength) != 0) && (length < restriction.MinLength))
         {
             return new XmlSchemaException("Sch_MinLengthConstraintFailed", string.Empty);
         }
         if (((flags & RestrictionFlags.MaxLength) != 0) && (restriction.MaxLength < length))
         {
             return new XmlSchemaException("Sch_MaxLengthConstraintFailed", string.Empty);
         }
         if (((flags & RestrictionFlags.Enumeration) != 0) && !this.MatchEnumeration(value, restriction.Enumeration, datatype))
         {
             return new XmlSchemaException("Sch_EnumerationConstraintFailed", string.Empty);
         }
     }
     return null;
 }
 internal override Exception CheckValueFacets(object value, XmlSchemaDatatype datatype)
 {
     RestrictionFacets restriction = datatype.Restriction;
     RestrictionFlags flags = (restriction != null) ? restriction.Flags : ((RestrictionFlags) 0);
     if (((flags & RestrictionFlags.Enumeration) != 0) && !this.MatchEnumeration(value, restriction.Enumeration, datatype))
     {
         return new XmlSchemaException("Sch_EnumerationConstraintFailed", string.Empty);
     }
     return null;
 }
 private bool MatchEnumeration(DateTime value, ArrayList enumeration, XmlSchemaDatatype datatype)
 {
     for (int i = 0; i < enumeration.Count; i++)
     {
         if (datatype.Compare(value, (DateTime) enumeration[i]) == 0)
         {
             return true;
         }
     }
     return false;
 }
Example #6
0
 private XElement GetNewElement(XName name, object value, XmlSchemaDatatype datatype, XElement parentElement) {
     XElement newElement = null;
     if (datatype != null) {
         string stringValue = XTypedServices.GetXmlString(value, datatype, parentElement);
         newElement = new XElement(name, stringValue);
     }
     else {
         newElement = XTypedServices.GetXElement(value as XTypedElement, name);
     }
     return newElement;
 }
 internal override bool MatchEnumeration(object value, ArrayList enumeration, XmlSchemaDatatype datatype)
 {
     for (int i = 0; i < enumeration.Count; i++)
     {
         if (datatype.Compare(value, enumeration[i]) == 0)
         {
             return true;
         }
     }
     return false;
 }
 public TypedObject(object obj, string svalue, XmlSchemaDatatype xsdtype)
 {
     this.ovalue = obj;
     this.svalue = svalue;
     this.xsdtype = xsdtype;
     if (((xsdtype.Variety == XmlSchemaDatatypeVariety.List) || (xsdtype is Datatype_base64Binary)) || (xsdtype is Datatype_hexBinary))
     {
         this.isList = true;
         this.dim = ((Array) obj).Length;
     }
 }
Example #9
0
 public FacetsCompiler(DatatypeImplementation baseDatatype, RestrictionFacets restriction) {
     firstPattern = true;
     regStr = null;
     pattern_facet = null;
     datatype = baseDatatype;
     derivedRestriction = restriction;
     baseFlags = datatype.Restriction != null ? datatype.Restriction.Flags : 0;
     baseFixedFlags = datatype.Restriction != null ? datatype.Restriction.FixedFlags : 0;
     validRestrictionFlags = datatype.ValidRestrictionFlags;
     nonNegativeInt = DatatypeImplementation.GetSimpleTypeFromTypeCode(XmlTypeCode.NonNegativeInteger).Datatype;
     builtInEnum = !(datatype is Datatype_union || datatype is Datatype_List) ? datatype.TypeCode : 0;
     builtInType = (int)builtInEnum > 0 ? DatatypeImplementation.GetSimpleTypeFromTypeCode(builtInEnum).Datatype : datatype;
 }
Example #10
0
 public FacetsCompiler(DatatypeImplementation baseDatatype, RestrictionFacets restriction)
 {
     _firstPattern = true;
     _regStr = null;
     _pattern_facet = null;
     _datatype = baseDatatype;
     _derivedRestriction = restriction;
     _baseFlags = _datatype.Restriction != null ? _datatype.Restriction.Flags : 0;
     _baseFixedFlags = _datatype.Restriction != null ? _datatype.Restriction.FixedFlags : 0;
     _validRestrictionFlags = _datatype.ValidRestrictionFlags;
     _nonNegativeInt = DatatypeImplementation.GetSimpleTypeFromTypeCode(XmlTypeCode.NonNegativeInteger).Datatype;
     _builtInEnum = !(_datatype is Datatype_union || _datatype is Datatype_List) ? _datatype.TypeCode : 0;
     _builtInType = (int)_builtInEnum > 0 ? DatatypeImplementation.GetSimpleTypeFromTypeCode(_builtInEnum).Datatype : _datatype;
 }
Example #11
0
 public virtual void AddElementToParent(XName name, object value, XElement parentElement, bool addToExisting, XmlSchemaDatatype datatype) {
     Debug.Assert(value != null);
     if (addToExisting) {
         parentElement.Add(GetNewElement(name, value, datatype, parentElement));
     }
     else {
         XElement existingElement = parentElement.Element(name);
         if (existingElement == null) {
             parentElement.Add(GetNewElement(name, value, datatype, parentElement));
         }
         else if (datatype != null) { //Update simple type value
             existingElement.Value = XTypedServices.GetXmlString(value, datatype, existingElement);
         }
         else {
             existingElement.AddBeforeSelf(XTypedServices.GetXElement(value as XTypedElement, name));
             existingElement.Remove();
         }
     }
 }
        internal override int Validate(ValidationEventHandler h, XmlSchema schema)
        {
            if (IsValidated(schema.ValidationId))
            {
                return(errorCount);
            }

            XmlSchemaType st = schema.FindSchemaType(baseTypeName);

            if (st != null)
            {
                XmlSchemaComplexType ct = st as XmlSchemaComplexType;
                if (ct != null && ct.ContentModel is XmlSchemaComplexContent)
                {
                    error(h, "Specified type is complex type which contains complex content.");
                }
                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);
 }
        internal override Exception CheckValueFacets(decimal value, XmlSchemaDatatype datatype)
        {
            RestrictionFacets restriction    = datatype.Restriction;
            RestrictionFlags  flags          = (restriction != null) ? restriction.Flags : ((RestrictionFlags)0);
            XmlValueConverter valueConverter = datatype.ValueConverter;

            if ((value > this.maxValue) || (value < this.minValue))
            {
                return(new OverflowException(Res.GetString("XmlConvert_Overflow", new object[] { value.ToString(CultureInfo.InvariantCulture), datatype.TypeCodeString })));
            }
            if (flags == 0)
            {
                return(null);
            }
            if (((flags & RestrictionFlags.MaxInclusive) != 0) && (value > valueConverter.ToDecimal(restriction.MaxInclusive)))
            {
                return(new XmlSchemaException("Sch_MaxInclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.MaxExclusive) != 0) && (value >= valueConverter.ToDecimal(restriction.MaxExclusive)))
            {
                return(new XmlSchemaException("Sch_MaxExclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.MinInclusive) != 0) && (value < valueConverter.ToDecimal(restriction.MinInclusive)))
            {
                return(new XmlSchemaException("Sch_MinInclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.MinExclusive) != 0) && (value <= valueConverter.ToDecimal(restriction.MinExclusive)))
            {
                return(new XmlSchemaException("Sch_MinExclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.Enumeration) != 0) && !this.MatchEnumeration(value, restriction.Enumeration, valueConverter))
            {
                return(new XmlSchemaException("Sch_EnumerationConstraintFailed", string.Empty));
            }
            return(this.CheckTotalAndFractionDigits(value, restriction.TotalDigits, restriction.FractionDigits, (flags & RestrictionFlags.TotalDigits) != 0, (flags & RestrictionFlags.FractionDigits) != 0));
        }
 private bool MatchEnumeration(string value, ArrayList enumeration, XmlSchemaDatatype datatype)
 {
     if (datatype.TypeCode == XmlTypeCode.AnyUri)
     {
         for (int i = 0; i < enumeration.Count; i++)
         {
             if (value.Equals(((Uri)enumeration[i]).OriginalString))
             {
                 return(true);
             }
         }
     }
     else
     {
         for (int j = 0; j < enumeration.Count; j++)
         {
             if (value.Equals((string)enumeration[j]))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
 internal bool ContainsIdAttribute(bool findAll)
 {
     int num = 0;
     foreach (XmlSchemaAttribute attribute in this.AttributeUses.Values)
     {
         if (attribute.Use != XmlSchemaUse.Prohibited)
         {
             XmlSchemaDatatype datatype = attribute.Datatype;
             if ((datatype != null) && (datatype.TypeCode == XmlTypeCode.Id))
             {
                 num++;
                 if (num > 1)
                 {
                     break;
                 }
             }
         }
     }
     if (!findAll)
     {
         return (num > 0);
     }
     return (num > 1);
 }
Example #17
0
 internal override Exception CheckValueFacets(object value, XmlSchemaDatatype datatype) {
     RestrictionFacets restriction = datatype.Restriction;
     RestrictionFlags flags = restriction != null ? restriction.Flags : 0;
     
     if ((flags & RestrictionFlags.Enumeration) != 0) {
         if (!MatchEnumeration(value, restriction.Enumeration, datatype)) {
             return new XmlSchemaException(Res.Sch_EnumerationConstraintFailed, string.Empty);
         }
     }
     return null;
 }
 internal SchemaElementDecl(XmlSchemaDatatype dtype, SchemaNames names)
 {
     Datatype            = dtype;
     Content             = new CompiledContentModel(names);
     Content.ContentType = CompiledContentModel.Type.Text;
 }
Example #19
0
 internal override bool MatchEnumeration(object value, ArrayList enumeration, XmlSchemaDatatype datatype) {
     return MatchEnumeration((byte[])value, enumeration, datatype);
 }
Example #20
0
 internal override Exception CheckValueFacets(object value, XmlSchemaDatatype datatype) {
     double doubleValue = datatype.ValueConverter.ToDouble(value);
     return CheckValueFacets(doubleValue, datatype);
 }
        private ValidationType DetectValidationType()
        {
            if ((base.reader.Schemas != null) && (base.reader.Schemas.Count > 0))
            {
                XmlSchemaCollectionEnumerator enumerator = base.reader.Schemas.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    SchemaInfo schemaInfo = enumerator.CurrentNode.SchemaInfo;
                    if (schemaInfo.SchemaType == SchemaType.XSD)
                    {
                        return(ValidationType.Schema);
                    }
                    if (schemaInfo.SchemaType == SchemaType.XDR)
                    {
                        return(ValidationType.XDR);
                    }
                }
            }
            if (base.reader.NodeType == XmlNodeType.Element)
            {
                switch (base.SchemaNames.SchemaTypeFromRoot(base.reader.LocalName, base.reader.NamespaceURI))
                {
                case SchemaType.XSD:
                    return(ValidationType.Schema);

                case SchemaType.XDR:
                    return(ValidationType.XDR);
                }
                int attributeCount = base.reader.AttributeCount;
                for (int i = 0; i < attributeCount; i++)
                {
                    base.reader.MoveToAttribute(i);
                    string namespaceURI = base.reader.NamespaceURI;
                    string localName    = base.reader.LocalName;
                    if (Ref.Equal(namespaceURI, base.SchemaNames.NsXmlNs))
                    {
                        if (XdrBuilder.IsXdrSchema(base.reader.Value))
                        {
                            base.reader.MoveToElement();
                            return(ValidationType.XDR);
                        }
                    }
                    else
                    {
                        if (Ref.Equal(namespaceURI, base.SchemaNames.NsXsi))
                        {
                            base.reader.MoveToElement();
                            return(ValidationType.Schema);
                        }
                        if (Ref.Equal(namespaceURI, base.SchemaNames.QnDtDt.Namespace) && Ref.Equal(localName, base.SchemaNames.QnDtDt.Name))
                        {
                            base.reader.SchemaTypeObject = XmlSchemaDatatype.FromXdrName(base.reader.Value);
                            base.reader.MoveToElement();
                            return(ValidationType.XDR);
                        }
                    }
                }
                if (attributeCount > 0)
                {
                    base.reader.MoveToElement();
                }
            }
            return(ValidationType.Auto);
        }
 private XmlQualifiedName QualifiedName(string name, string ns)
 {
     return(new XmlQualifiedName(name, XmlSchemaDatatype.XdrCanonizeUri(ns, base.NameTable, base.SchemaNames)));
 }
Example #23
0
 internal virtual bool MatchEnumeration(object value, ArrayList enumeration, XmlSchemaDatatype datatype) {
     return false;
 }
Example #24
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);
        }
 private void CheckValue(string value, SchemaAttDef attdef)
 {
     try
     {
         base.reader.TypedValueObject = null;
         bool flag = attdef != null;
         XmlSchemaDatatype datatype = flag ? attdef.Datatype : base.context.ElementDecl.Datatype;
         if (datatype != null)
         {
             if (datatype.TokenizedType != XmlTokenizedType.CDATA)
             {
                 value = value.Trim();
             }
             if (value.Length != 0)
             {
                 object pVal = datatype.ParseValue(value, base.NameTable, this.nsManager);
                 base.reader.TypedValueObject = pVal;
                 switch (datatype.TokenizedType)
                 {
                 case XmlTokenizedType.ENTITY:
                 case XmlTokenizedType.ID:
                 case XmlTokenizedType.IDREF:
                     if (datatype.Variety == XmlSchemaDatatypeVariety.List)
                     {
                         string[] strArray = (string[])pVal;
                         for (int i = 0; i < strArray.Length; i++)
                         {
                             this.ProcessTokenizedType(datatype.TokenizedType, strArray[i]);
                         }
                     }
                     else
                     {
                         this.ProcessTokenizedType(datatype.TokenizedType, (string)pVal);
                     }
                     break;
                 }
                 SchemaDeclBase base2 = flag ? ((SchemaDeclBase)attdef) : ((SchemaDeclBase)base.context.ElementDecl);
                 if ((base2.MaxLength != 0xffffffffL) && (value.Length > base2.MaxLength))
                 {
                     base.SendValidationEvent("Sch_MaxLengthConstraintFailed", value);
                 }
                 if ((base2.MinLength != 0xffffffffL) && (value.Length < base2.MinLength))
                 {
                     base.SendValidationEvent("Sch_MinLengthConstraintFailed", value);
                 }
                 if ((base2.Values != null) && !base2.CheckEnumeration(pVal))
                 {
                     if (datatype.TokenizedType == XmlTokenizedType.NOTATION)
                     {
                         base.SendValidationEvent("Sch_NotationValue", pVal.ToString());
                     }
                     else
                     {
                         base.SendValidationEvent("Sch_EnumerationValue", pVal.ToString());
                     }
                 }
                 if (!base2.CheckValue(pVal))
                 {
                     if (flag)
                     {
                         base.SendValidationEvent("Sch_FixedAttributeValue", attdef.Name.ToString());
                     }
                     else
                     {
                         base.SendValidationEvent("Sch_FixedElementValue", XmlSchemaValidator.QNameString(base.context.LocalName, base.context.Namespace));
                     }
                 }
             }
         }
     }
     catch (XmlSchemaException)
     {
         if (attdef != null)
         {
             base.SendValidationEvent("Sch_AttributeValueDataType", attdef.Name.ToString());
         }
         else
         {
             base.SendValidationEvent("Sch_ElementValueDataType", XmlSchemaValidator.QNameString(base.context.LocalName, base.context.Namespace));
         }
     }
 }
Example #26
0
        public static void CheckDefaultValue(
            string value,
            SchemaAttDef attdef,
            SchemaInfo sinfo,
            XmlNamespaceManager nsManager,
            XmlNameTable NameTable,
            object sender,
            ValidationEventHandler eventhandler,
            string baseUri,
            int lineNo,
            int linePos
            )
        {
            try
            {
                XmlSchemaDatatype dtype = attdef.Datatype;
                if (dtype == null)
                {
                    return; // no reason to check
                }

                if (dtype.TokenizedType != XmlTokenizedType.CDATA)
                {
                    value = value.Trim();
                }
                if (value.Length == 0)
                {
                    return; // don't need to check
                }
                object typedValue = dtype.ParseValue(value, NameTable, nsManager);

                // Check special types
                XmlTokenizedType ttype = dtype.TokenizedType;
                if (ttype == XmlTokenizedType.ENTITY)
                {
                    if (dtype.Variety == XmlSchemaDatatypeVariety.List)
                    {
                        string[] ss = (string[])typedValue;
                        for (int i = 0; i < ss.Length; ++i)
                        {
                            ProcessEntity(sinfo, ss[i], sender, eventhandler, baseUri, lineNo, linePos);
                        }
                    }
                    else
                    {
                        ProcessEntity(sinfo, (string)typedValue, sender, eventhandler, baseUri, lineNo, linePos);
                    }
                }
                else if (ttype == XmlTokenizedType.ENUMERATION)
                {
                    if (!attdef.CheckEnumeration(typedValue))
                    {
                        XmlSchemaException e = new XmlSchemaException(SR.Sch_EnumerationValue, typedValue.ToString(), baseUri, lineNo, linePos);
                        if (eventhandler != null)
                        {
                            eventhandler(sender, new ValidationEventArgs(e));
                        }
                        else
                        {
                            throw e;
                        }
                    }
                }
                attdef.DefaultValueTyped = typedValue;
            }
#if DEBUG
            catch (XmlSchemaException ex)
            {
                Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, ex.Message);
#else
            catch
            {
#endif
                XmlSchemaException e = new XmlSchemaException(SR.Sch_AttributeDefaultDataType, attdef.Name.ToString(), baseUri, lineNo, linePos);
                if (eventhandler != null)
                {
                    eventhandler(sender, new ValidationEventArgs(e));
                }
                else
                {
                    throw e;
                }
            }
        }
Example #27
0
        private void CheckValue(
            string value,
            SchemaAttDef attdef
            )
        {
            try
            {
                reader.TypedValueObject = null;
                bool isAttn             = attdef != null;
                XmlSchemaDatatype dtype = isAttn ? attdef.Datatype : context.ElementDecl.Datatype;
                if (dtype == null)
                {
                    return; // no reason to check
                }

                if (dtype.TokenizedType != XmlTokenizedType.CDATA)
                {
                    value = value.Trim();
                }
                if (value.Length == 0)
                {
                    return; // don't need to check
                }


                object typedValue = dtype.ParseValue(value, NameTable, _nsManager);
                reader.TypedValueObject = typedValue;
                // Check special types
                XmlTokenizedType ttype = dtype.TokenizedType;
                if (ttype == XmlTokenizedType.ENTITY || ttype == XmlTokenizedType.ID || ttype == XmlTokenizedType.IDREF)
                {
                    if (dtype.Variety == XmlSchemaDatatypeVariety.List)
                    {
                        string[] ss = (string[])typedValue;
                        for (int i = 0; i < ss.Length; ++i)
                        {
                            ProcessTokenizedType(dtype.TokenizedType, ss[i]);
                        }
                    }
                    else
                    {
                        ProcessTokenizedType(dtype.TokenizedType, (string)typedValue);
                    }
                }

                SchemaDeclBase decl = isAttn ? (SchemaDeclBase)attdef : (SchemaDeclBase)context.ElementDecl;

                if (decl.MaxLength != uint.MaxValue)
                {
                    if (value.Length > decl.MaxLength)
                    {
                        SendValidationEvent(SR.Sch_MaxLengthConstraintFailed, value);
                    }
                }
                if (decl.MinLength != uint.MaxValue)
                {
                    if (value.Length < decl.MinLength)
                    {
                        SendValidationEvent(SR.Sch_MinLengthConstraintFailed, value);
                    }
                }
                if (decl.Values != null && !decl.CheckEnumeration(typedValue))
                {
                    if (dtype.TokenizedType == XmlTokenizedType.NOTATION)
                    {
                        SendValidationEvent(SR.Sch_NotationValue, typedValue.ToString());
                    }
                    else
                    {
                        SendValidationEvent(SR.Sch_EnumerationValue, typedValue.ToString());
                    }
                }
                if (!decl.CheckValue(typedValue))
                {
                    if (isAttn)
                    {
                        SendValidationEvent(SR.Sch_FixedAttributeValue, attdef.Name.ToString());
                    }
                    else
                    {
                        SendValidationEvent(SR.Sch_FixedElementValue, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace));
                    }
                }
            }
            catch (XmlSchemaException)
            {
                if (attdef != null)
                {
                    SendValidationEvent(SR.Sch_AttributeValueDataType, attdef.Name.ToString());
                }
                else
                {
                    SendValidationEvent(SR.Sch_ElementValueDataType, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace));
                }
            }
        }
Example #28
0
        public static void CheckDefaultValue(
            SchemaAttDef attdef,
            SchemaInfo sinfo,
            IValidationEventHandling eventHandling,
            string baseUriStr
            )
        {
            try {
                if (baseUriStr == null)
                {
                    baseUriStr = string.Empty;
                }
                XmlSchemaDatatype dtype = attdef.Datatype;
                if (dtype == null)
                {
                    return; // no reason to check
                }
                object typedValue = attdef.DefaultValueTyped;

                // Check special types
                XmlTokenizedType ttype = dtype.TokenizedType;
                if (ttype == XmlTokenizedType.ENTITY)
                {
                    if (dtype.Variety == XmlSchemaDatatypeVariety.List)
                    {
                        string[] ss = (string[])typedValue;
                        for (int i = 0; i < ss.Length; ++i)
                        {
                            ProcessEntity(sinfo, ss[i], eventHandling, baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
                        }
                    }
                    else
                    {
                        ProcessEntity(sinfo, (string)typedValue, eventHandling, baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
                    }
                }
                else if (ttype == XmlTokenizedType.ENUMERATION)
                {
                    if (!attdef.CheckEnumeration(typedValue))
                    {
                        if (eventHandling != null)
                        {
                            XmlSchemaException e = new XmlSchemaException(Res.Sch_EnumerationValue, typedValue.ToString(), baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
                            eventHandling.SendEvent(e, XmlSeverityType.Error);
                        }
                    }
                }
            }
#if DEBUG
            catch (XmlSchemaException ex) {
                Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, ex.Message);
#else
            catch (Exception)  {
#endif

                if (eventHandling != null)
                {
                    XmlSchemaException e = new XmlSchemaException(Res.Sch_AttributeDefaultDataType, attdef.Name.ToString());
                    eventHandling.SendEvent(e, XmlSeverityType.Error);
                }
            }
        }
Example #29
0
 internal virtual Exception CheckLexicalFacets(ref string parseString, XmlSchemaDatatype datatype) {
     CheckWhitespaceFacets(ref parseString, datatype);
     return CheckPatternFacets(datatype.Restriction, parseString);
 }
        internal override Exception CheckValueFacets(object value, XmlSchemaDatatype datatype)
        {
            decimal num = datatype.ValueConverter.ToDecimal(value);

            return(this.CheckValueFacets(num, datatype));
        }
Example #31
0
 internal virtual Exception CheckValueFacets(XmlQualifiedName value, XmlSchemaDatatype datatype) {
     return null;
 }
 internal override bool MatchEnumeration(object value, ArrayList enumeration, XmlSchemaDatatype datatype)
 {
     return(this.MatchEnumeration(datatype.ValueConverter.ToDecimal(value), enumeration, datatype.ValueConverter));
 }
Example #33
0
        internal override Exception CheckValueFacets(decimal value, XmlSchemaDatatype datatype) {
            RestrictionFacets restriction = datatype.Restriction;
            RestrictionFlags flags = restriction != null ? restriction.Flags : 0;
            XmlValueConverter valueConverter = datatype.ValueConverter;
            
            //Check built-in facets
            if (value > maxValue || value < minValue) {
                return new OverflowException(Res.GetString(Res.XmlConvert_Overflow, value.ToString(CultureInfo.InvariantCulture), datatype.TypeCodeString));
            }
            //Check user-defined facets
            if (flags != 0) {
                if ((flags & RestrictionFlags.MaxInclusive) != 0) {
                    if (value > valueConverter.ToDecimal(restriction.MaxInclusive)) {
                        return new XmlSchemaException(Res.Sch_MaxInclusiveConstraintFailed, string.Empty);
                    }
                }

                if ((flags & RestrictionFlags.MaxExclusive) != 0) {
                    if (value >= valueConverter.ToDecimal(restriction.MaxExclusive)) {
                        return new XmlSchemaException(Res.Sch_MaxExclusiveConstraintFailed, string.Empty);
                    }
                }

                if ((flags & RestrictionFlags.MinInclusive) != 0) {
                    if (value < valueConverter.ToDecimal(restriction.MinInclusive)) {
                        return new XmlSchemaException(Res.Sch_MinInclusiveConstraintFailed, string.Empty);
                    }
                }
                
                if ((flags & RestrictionFlags.MinExclusive) != 0) {
                    if (value <= valueConverter.ToDecimal(restriction.MinExclusive)) {
                        return new XmlSchemaException(Res.Sch_MinExclusiveConstraintFailed, string.Empty);
                    }
                }
                if ((flags & RestrictionFlags.Enumeration) != 0) {
                    if (!MatchEnumeration(value, restriction.Enumeration, valueConverter)) {
                        return new XmlSchemaException(Res.Sch_EnumerationConstraintFailed, string.Empty);
                    }
                }
                return CheckTotalAndFractionDigits(value, restriction.TotalDigits, restriction.FractionDigits, ((flags & RestrictionFlags.TotalDigits) != 0), ((flags & RestrictionFlags.FractionDigits) != 0));
            }
            return null;
        }
Example #34
0
 public virtual bool IsDerivedFrom(XmlSchemaDatatype datatype)
 {
     return(false);
 }
Example #35
0
 internal override bool MatchEnumeration(object value, ArrayList enumeration, XmlSchemaDatatype datatype) {
     return MatchEnumeration(datatype.ValueConverter.ToDouble(value), enumeration, datatype.ValueConverter);
 }
Example #36
0
 internal class BinaryFacetsChecker : FacetsChecker { //hexBinary & Base64Binary
     
     internal override Exception CheckValueFacets(object value, XmlSchemaDatatype datatype) {
         byte[] byteArrayValue = (byte[])value;
         return CheckValueFacets(byteArrayValue, datatype);
     }
Example #37
0
 internal abstract bool IsComparable(XmlSchemaDatatype dtype);
        internal override Exception CheckValueFacets(object value, XmlSchemaDatatype datatype)
        {
            TimeSpan span = (TimeSpan)datatype.ValueConverter.ChangeType(value, typeof(TimeSpan));

            return(this.CheckValueFacets(span, datatype));
        }
        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 Exception CheckValueFacets(int value, XmlSchemaDatatype datatype)
        {
            decimal num = value;

            return(this.CheckValueFacets(num, datatype));
        }
Example #41
0
 internal override Exception CheckValueFacets(byte[] value, XmlSchemaDatatype datatype) {
     //Length, MinLength, MaxLength
     RestrictionFacets restriction = datatype.Restriction;
     int length = value.Length;
     RestrictionFlags flags = restriction != null ? restriction.Flags : 0;
     if (flags != 0) { //if it has facets defined
         if ((flags & RestrictionFlags.Length) != 0) {
             if (restriction.Length != length) {
                 return new XmlSchemaException(Res.Sch_LengthConstraintFailed, string.Empty);
             }
         }
         if ((flags & RestrictionFlags.MinLength) != 0) {
             if (length < restriction.MinLength) {
                 return new XmlSchemaException(Res.Sch_MinLengthConstraintFailed, string.Empty);
             }
         }
         if ((flags & RestrictionFlags.MaxLength) != 0) {
             if (restriction.MaxLength < length) {
                 return new XmlSchemaException(Res.Sch_MaxLengthConstraintFailed, string.Empty);
             }
         }
         if ((flags & RestrictionFlags.Enumeration) != 0) {
             if (!MatchEnumeration(value, restriction.Enumeration, datatype)) {
                 return new XmlSchemaException(Res.Sch_EnumerationConstraintFailed, string.Empty);
             }
         }
     }
     return null;
 }
 internal SchemaElementDecl(XmlSchemaDatatype dtype)
 {
     Datatype          = dtype;
     _contentValidator = ContentValidator.TextOnly;
 }
Example #43
0
        internal override Exception CheckValueFacets(object value, XmlSchemaDatatype datatype) {
            //Check for facets allowed on lists - Length, MinLength, MaxLength
            Array values = value as Array;
            Debug.Assert(values != null);

            RestrictionFacets restriction = datatype.Restriction;
            RestrictionFlags flags = restriction != null ? restriction.Flags : 0;
            
            if ((flags & (RestrictionFlags.Length|RestrictionFlags.MinLength|RestrictionFlags.MaxLength)) != 0) {
                int length = values.Length;
                if ((flags & RestrictionFlags.Length) != 0) {
                    if (restriction.Length != length) {
                        return new XmlSchemaException(Res.Sch_LengthConstraintFailed, string.Empty);
                    }
                }

                if ((flags & RestrictionFlags.MinLength) != 0) {
                    if (length < restriction.MinLength) {
                        return new XmlSchemaException(Res.Sch_MinLengthConstraintFailed, string.Empty);
                    }
                }

                if ((flags & RestrictionFlags.MaxLength) != 0) {
                    if (restriction.MaxLength < length) {
                        return new XmlSchemaException(Res.Sch_MaxLengthConstraintFailed, string.Empty);
                    }
                }
            }
            if ((flags & RestrictionFlags.Enumeration) != 0) {
                if (!MatchEnumeration(value, restriction.Enumeration, datatype)) {
                    return new XmlSchemaException(Res.Sch_EnumerationConstraintFailed, string.Empty);
                }
            }
            return null;
        }
 internal override bool MatchEnumeration(object value, ArrayList enumeration, XmlSchemaDatatype datatype)
 {
     return(this.MatchEnumeration((TimeSpan)value, enumeration));
 }
Example #45
0
 internal override bool MatchEnumeration(object value, ArrayList enumeration, XmlSchemaDatatype datatype) {
     for (int i = 0; i < enumeration.Count; ++i) {
         if (datatype.Compare(value, enumeration[i]) == 0) { //Compare on Datatype_union will compare two XsdSimpleValue
             return true;
         }
     }
     return false;
 }
        private void CheckValue(
            string value,
            SchemaAttDef attdef
            )
        {
            try {
                reader.TypedValueObject = null;
                bool isAttn             = attdef != null;
                XmlSchemaDatatype dtype = isAttn ? attdef.Datatype : context.ElementDecl.Datatype;
                if (dtype == null)
                {
                    return; // no reason to check
                }

                object typedValue = dtype.ParseValue(value, NameTable, nsManager, true);

                // Check special types
                XmlTokenizedType ttype = dtype.TokenizedType;
                if (ttype == XmlTokenizedType.ENTITY || ttype == XmlTokenizedType.ID || ttype == XmlTokenizedType.IDREF)
                {
                    if (dtype.Variety == XmlSchemaDatatypeVariety.List)
                    {
                        string[] ss = (string[])typedValue;
                        for (int i = 0; i < ss.Length; ++i)
                        {
                            ProcessTokenizedType(dtype.TokenizedType, ss[i]);
                        }
                    }
                    else
                    {
                        ProcessTokenizedType(dtype.TokenizedType, (string)typedValue);
                    }
                }

                SchemaDeclBase decl = isAttn ? (SchemaDeclBase)attdef : (SchemaDeclBase)context.ElementDecl;
                if (!decl.CheckValue(typedValue))
                {
                    if (isAttn)
                    {
                        SendValidationEvent(Res.Sch_FixedAttributeValue, attdef.Name.ToString());
                    }
                    else
                    {
                        SendValidationEvent(Res.Sch_FixedElementValue, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace));
                    }
                }
                if (dtype.Variety == XmlSchemaDatatypeVariety.Union)
                {
                    typedValue = UnWrapUnion(typedValue);
                }
                reader.TypedValueObject = typedValue;
            }
            catch (XmlSchemaException) {
                if (attdef != null)
                {
                    SendValidationEvent(Res.Sch_AttributeValueDataType, attdef.Name.ToString());
                }
                else
                {
                    SendValidationEvent(Res.Sch_ElementValueDataType, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace));
                }
            }
        }
Example #47
0
 private object ParseFacetValue(XmlSchemaDatatype datatype, XmlSchemaFacet facet, string code, IXmlNamespaceResolver nsmgr, XmlNameTable nameTable) {
     object typedValue;
     Exception ex = datatype.TryParseValue(facet.Value, nameTable, nsmgr, out typedValue);
     if (ex == null) {
         return typedValue;
     }
     else {
         throw new XmlSchemaException(code, new string[] {ex.Message} , ex, facet.SourceUri, facet.LineNumber, facet.LinePosition, facet);
     }
 }
Example #48
0
 internal void SetDatatype(XmlSchemaDatatype value)
 {
     datatype = value;
 }
Example #49
0
 internal virtual Exception CheckValueFacets(TimeSpan value, XmlSchemaDatatype datatype) {
     return null;
 }
Example #50
0
 internal static bool IsDerivedFromDatatype(XmlSchemaDatatype derivedDataType, XmlSchemaDatatype baseDataType, XmlSchemaDerivationMethod except)
 {
     if (DatatypeImplementation.AnySimpleType.Datatype == baseDataType)
     {
         return(true);
     }
     return(derivedDataType.IsDerivedFrom(baseDataType));
 }
Example #51
0
        internal void CheckWhitespaceFacets(ref string s, XmlSchemaDatatype datatype) {
            // before parsing, check whitespace facet
            RestrictionFacets restriction = datatype.Restriction;

            switch (datatype.Variety) {
                case XmlSchemaDatatypeVariety.List:
                    s = s.Trim();
                break;

                case XmlSchemaDatatypeVariety.Atomic:
                    if (datatype.BuiltInWhitespaceFacet == XmlSchemaWhiteSpace.Collapse) {
                        s = XmlComplianceUtil.NonCDataNormalize(s);
                    }
                    else if (datatype.BuiltInWhitespaceFacet == XmlSchemaWhiteSpace.Replace) {
                        s = XmlComplianceUtil.CDataNormalize(s);
                    }
                    else if (restriction != null && (restriction.Flags & RestrictionFlags.WhiteSpace) != 0) { //Restriction has whitespace facet specified
                        if (restriction.WhiteSpace == XmlSchemaWhiteSpace.Replace) {
                            s = XmlComplianceUtil.CDataNormalize(s);
                        }
                        else if (restriction.WhiteSpace == XmlSchemaWhiteSpace.Collapse) {
                            s = XmlComplianceUtil.NonCDataNormalize(s);
                        }
                    }
                break;

                default:
                break;

            }
        }
Example #52
0
        private ValidationType DetectValidationType()
        {
            //Type not yet detected : Check in Schema Collection
            if (reader.Schemas != null && reader.Schemas.Count > 0)
            {
                XmlSchemaCollectionEnumerator enumerator = reader.Schemas.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    XmlSchemaCollectionNode node = enumerator.CurrentNode !;
                    SchemaInfo schemaInfo        = node.SchemaInfo !;
                    if (schemaInfo.SchemaType == SchemaType.XSD)
                    {
                        return(ValidationType.Schema);
                    }
                    else if (schemaInfo.SchemaType == SchemaType.XDR)
                    {
                        return(ValidationType.XDR);
                    }
                }
            }

            if (reader.NodeType == XmlNodeType.Element)
            {
                SchemaType schemaType = SchemaNames.SchemaTypeFromRoot(reader.LocalName, reader.NamespaceURI);
                if (schemaType == SchemaType.XSD)
                {
                    return(ValidationType.Schema);
                }
                else if (schemaType == SchemaType.XDR)
                {
                    return(ValidationType.XDR);
                }
                else
                {
                    int count = reader.AttributeCount;
                    for (int i = 0; i < count; i++)
                    {
                        reader.MoveToAttribute(i);
                        string objectNs   = reader.NamespaceURI;
                        string objectName = reader.LocalName;
                        if (Ref.Equal(objectNs, SchemaNames.NsXmlNs))
                        {
                            if (XdrBuilder.IsXdrSchema(reader.Value))
                            {
                                reader.MoveToElement();
                                return(ValidationType.XDR);
                            }
                        }
                        else if (Ref.Equal(objectNs, SchemaNames.NsXsi))
                        {
                            reader.MoveToElement();
                            return(ValidationType.Schema);
                        }
                        else if (Ref.Equal(objectNs, SchemaNames.QnDtDt.Namespace) && Ref.Equal(objectName, SchemaNames.QnDtDt.Name))
                        {
                            reader.SchemaTypeObject = XmlSchemaDatatype.FromXdrName(reader.Value);
                            reader.MoveToElement();
                            return(ValidationType.XDR);
                        }
                    } //end of for
                    if (count > 0)
                    {
                        reader.MoveToElement();
                    }
                }
            }
            return(ValidationType.Auto);
        }
Example #53
0
        internal override Exception CheckValueFacets(object value, XmlSchemaDatatype datatype) {

            decimal decimalValue = datatype.ValueConverter.ToDecimal(value);
            return CheckValueFacets(decimalValue, datatype);
        }
 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);
 }
Example #55
0
 internal override Exception CheckValueFacets(byte value, XmlSchemaDatatype datatype) {
     decimal decimalValue = (decimal)value;
     return CheckValueFacets(decimalValue, datatype);
 }
        internal override Exception CheckValueFacets(object value, XmlSchemaDatatype datatype)
        {
            DateTime time = datatype.ValueConverter.ToDateTime(value);

            return(this.CheckValueFacets(time, datatype));
        }
Example #57
0
 internal override Exception CheckValueFacets(float value, XmlSchemaDatatype datatype) {
     double doubleValue = (double)value;
     return CheckValueFacets(doubleValue, datatype);
 }
Example #58
0
 internal bool IsDerivedFrom(XmlSchemaDatatype dtype)
 {
     return(((DatatypeImplementation)this).IsDerivedFrom(dtype));
 }
Example #59
0
 internal override Exception CheckValueFacets(object value, XmlSchemaDatatype datatype) {
     TimeSpan timeSpanValue = (TimeSpan)datatype.ValueConverter.ChangeType(value, typeof(TimeSpan));
     return CheckValueFacets(timeSpanValue, datatype);
 }
 internal static XmlSchemaDatatype FromName(XmlQualifiedName qname)
 {
     return(XmlSchemaDatatype.FromName(qname.Name, qname.Namespace));
 }