Exemple #1
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(ResXml.Sch_EnumerationValue, typedValue.ToString(), baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
                            eventHandling.SendEvent(e, XmlSeverityType.Error);
                        }
                    }
                }
            }
#if DEBUG && disabled
            catch (XmlSchemaException ex) {
                Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, ex.Message);
#else
            catch (Exception)
            {
#endif

                if (eventHandling != null)
                {
                    XmlSchemaException e = new XmlSchemaException(ResXml.Sch_AttributeDefaultDataType, attdef.Name.ToString());
                    eventHandling.SendEvent(e, XmlSeverityType.Error);
                }
            }
        }
Exemple #2
0
 internal static bool IsDerivedFromDatatype(XmlSchemaDatatype derivedDataType, XmlSchemaDatatype baseDataType, XmlSchemaDerivationMethod except)
 {
     if (DatatypeImplementation.AnySimpleType.Datatype == baseDataType)
     {
         return(true);
     }
     return(derivedDataType.IsDerivedFrom(baseDataType));
 }
Exemple #3
0
        //check the contents of this attribute to ensure it is valid according to the specified attribute type.
        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();
                }

                object typedValue = dtype.ParseValue(value, NameTable, s_namespaceManager);
                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.Values != null && !decl.CheckEnumeration(typedValue))
                {
                    if (dtype.TokenizedType == XmlTokenizedType.NOTATION)
                    {
                        SendValidationEvent(ResXml.Sch_NotationValue, typedValue.ToString());
                    }
                    else
                    {
                        SendValidationEvent(ResXml.Sch_EnumerationValue, typedValue.ToString());
                    }
                }
                if (!decl.CheckValue(typedValue))
                {
                    if (isAttn)
                    {
                        SendValidationEvent(ResXml.Sch_FixedAttributeValue, attdef.Name.ToString());
                    }
                    else
                    {
                        SendValidationEvent(ResXml.Sch_FixedElementValue, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace));
                    }
                }
            }
            catch (XmlSchemaException)
            {
                if (attdef != null)
                {
                    SendValidationEvent(ResXml.Sch_AttributeValueDataType, attdef.Name.ToString());
                }
                else
                {
                    SendValidationEvent(ResXml.Sch_ElementValueDataType, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace));
                }
            }
        }
Exemple #4
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);
        }
Exemple #5
0
 internal void SetDatatype(XmlSchemaDatatype value)
 {
     _datatype = value;
 }
Exemple #6
0
 private XmlQualifiedName QualifiedName(string name, string ns)
 {
     return(new XmlQualifiedName(name, XmlSchemaDatatype.XdrCanonizeUri(ns, NameTable, SchemaNames)));
 }
Exemple #7
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(ResXml.Sch_EnumerationValue, typedValue.ToString(), baseUri, lineNo, linePos);
                        if (eventhandler != null)
                        {
                            eventhandler(sender, new ValidationEventArgs(e));
                        }
                        else
                        {
                            throw e;
                        }
                    }
                }
                attdef.DefaultValueTyped = typedValue;
            }
#if DEBUG && disabled
            catch (XmlSchemaException ex) {
                Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, ex.Message);
#else
            catch
            {
#endif
                XmlSchemaException e = new XmlSchemaException(ResXml.Sch_AttributeDefaultDataType, attdef.Name.ToString(), baseUri, lineNo, linePos);
                if (eventhandler != null)
                {
                    eventhandler(sender, new ValidationEventArgs(e));
                }
                else
                {
                    throw e;
                }
            }
        }
 internal abstract bool IsComparable(XmlSchemaDatatype dtype);
 /// <include file='doc\XmlSchemaDatatype.uex' path='docs/doc[@for="XmlSchemaDatatype.IsDerivedFrom"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public virtual bool IsDerivedFrom(XmlSchemaDatatype datatype)
 {
     return(false);
 }
Exemple #10
0
 internal SchemaElementDecl(XmlSchemaDatatype dtype)
 {
     Datatype          = dtype;
     _contentValidator = ContentValidator.TextOnly;
 }