Example #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);
                }
            }
        }
Example #2
0
 public AutoValidator(XmlValidatingReaderImpl reader, XmlSchemaCollection schemaCollection, IValidationEventHandling eventHandling) : base(reader, schemaCollection, eventHandling)
 {
     schemaInfo = new SchemaInfo();
 }
Example #3
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 #4
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;
                }
            }
        }