Inheritance: System.SystemException
Example #1
0
 private void ProcessException(System.Xml.Schema.XmlSchemaException ex)
 {
     // If stack traces is empty then...
     if (ex.StackTrace == null)
     {
         try
         {
             throw new System.Xml.Schema.XmlSchemaException(ex.Message, ex, ex.LineNumber, ex.LinePosition);
         }
         catch (System.Xml.Schema.XmlSchemaException ex1)
         {
             //Dim remoteStackTraceString As Reflection.FieldInfo = GetType(Exception).GetField("_remoteStackTraceString", Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic)
             // to the current InnerException.StackTrace
             //remoteStackTraceString.SetValue(ex, New StackTrace(True).ToString())
             ex = ex1;
         }
     }
     Exceptions.Add(ex);
     ex.Data.Add("XSD", _xsd);
     if (!string.IsNullOrEmpty(_xmlPath))
     {
         ex.Data.Add("XML Path", _xmlPath);
     }
     if (_xml.Length > 8192)
     {
         ex.Data.Add("XML Size", _xml.Length.ToString("#,##0"));
         _xml = _xml.Substring(0, 8192);
     }
     ex.Data.Add("XML", _xml);
 }
Example #2
0
		public void DenyUnrestricted ()
		{
			// can we call everything without a SecurityException ?
			XmlSchemaException xe = new XmlSchemaException (String.Empty, null);
			Assert.AreEqual (0, xe.LineNumber, "LineNumber");
			Assert.AreEqual (0, xe.LinePosition, "LinePosition");
			Assert.IsNotNull (xe.Message, "Message");
			Assert.IsNull (xe.SourceSchemaObject, "SourceSchemaObject");
			Assert.IsNull (xe.SourceUri, "SourceUri");
		}
 protected void SendValidationEvent(XmlSchemaException e, XmlSeverityType severity)
 {
     if (this.eventHandling != null)
     {
         this.eventHandling.SendEvent(e, severity);
     }
     else if (severity == XmlSeverityType.Error)
     {
         throw e;
     }
 }
Example #4
0
 private void SendValidationEvent(XmlSchemaException e)
 {
     if (validationEventHandler != null)
     {
         validationEventHandler(this, new ValidationEventArgs(e));
     }
     else
     {
         throw e;
     }
 }
 protected void SendValidationEvent(XmlSchemaException e, XmlSeverityType severity)
 {
     if (eventHandler != null)
     {
         eventHandler(reader, new ValidationEventArgs(e, severity));
     }
     else if (severity == XmlSeverityType.Error)
     {
         throw e;
     }
 }
 protected void SendValidationEventNoThrow(XmlSchemaException e, XmlSeverityType severity)
 {
     if (severity == XmlSeverityType.Error)
     {
         _errorCount++;
     }
     if (_eventHandler != null)
     {
         _eventHandler(null, new ValidationEventArgs(e, severity));
     }
 }
 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 datatype = attdef.Datatype;
         if (datatype != null)
         {
             if (datatype.TokenizedType != XmlTokenizedType.CDATA)
             {
                 value = value.Trim();
             }
             if (value.Length != 0)
             {
                 object pVal = datatype.ParseValue(value, NameTable, nsManager);
                 XmlTokenizedType tokenizedType = datatype.TokenizedType;
                 if (tokenizedType == XmlTokenizedType.ENTITY)
                 {
                     if (datatype.Variety == XmlSchemaDatatypeVariety.List)
                     {
                         string[] strArray = (string[]) pVal;
                         for (int i = 0; i < strArray.Length; i++)
                         {
                             BaseValidator.ProcessEntity(sinfo, strArray[i], sender, eventhandler, baseUri, lineNo, linePos);
                         }
                     }
                     else
                     {
                         BaseValidator.ProcessEntity(sinfo, (string) pVal, sender, eventhandler, baseUri, lineNo, linePos);
                     }
                 }
                 else if ((tokenizedType == XmlTokenizedType.ENUMERATION) && !attdef.CheckEnumeration(pVal))
                 {
                     XmlSchemaException ex = new XmlSchemaException("Sch_EnumerationValue", pVal.ToString(), baseUri, lineNo, linePos);
                     if (eventhandler == null)
                     {
                         throw ex;
                     }
                     eventhandler(sender, new ValidationEventArgs(ex));
                 }
                 attdef.DefaultValueTyped = pVal;
             }
         }
     }
     catch
     {
         XmlSchemaException exception2 = new XmlSchemaException("Sch_AttributeDefaultDataType", attdef.Name.ToString(), baseUri, lineNo, linePos);
         if (eventhandler == null)
         {
             throw exception2;
         }
         eventhandler(sender, new ValidationEventArgs(exception2));
     }
 }
 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 datatype = attdef.Datatype;
         if (datatype != null)
         {
             if (datatype.TokenizedType != XmlTokenizedType.CDATA)
             {
                 value = value.Trim();
             }
             if (value.Length != 0)
             {
                 object           pVal          = datatype.ParseValue(value, NameTable, nsManager);
                 XmlTokenizedType tokenizedType = datatype.TokenizedType;
                 if (tokenizedType == XmlTokenizedType.ENTITY)
                 {
                     if (datatype.Variety == XmlSchemaDatatypeVariety.List)
                     {
                         string[] strArray = (string[])pVal;
                         for (int i = 0; i < strArray.Length; i++)
                         {
                             BaseValidator.ProcessEntity(sinfo, strArray[i], sender, eventhandler, baseUri, lineNo, linePos);
                         }
                     }
                     else
                     {
                         BaseValidator.ProcessEntity(sinfo, (string)pVal, sender, eventhandler, baseUri, lineNo, linePos);
                     }
                 }
                 else if ((tokenizedType == XmlTokenizedType.ENUMERATION) && !attdef.CheckEnumeration(pVal))
                 {
                     XmlSchemaException ex = new XmlSchemaException("Sch_EnumerationValue", pVal.ToString(), baseUri, lineNo, linePos);
                     if (eventhandler == null)
                     {
                         throw ex;
                     }
                     eventhandler(sender, new ValidationEventArgs(ex));
                 }
                 attdef.DefaultValueTyped = pVal;
             }
         }
     }
     catch
     {
         XmlSchemaException exception2 = new XmlSchemaException("Sch_AttributeDefaultDataType", attdef.Name.ToString(), baseUri, lineNo, linePos);
         if (eventhandler == null)
         {
             throw exception2;
         }
         eventhandler(sender, new ValidationEventArgs(exception2));
     }
 }
        public static void CheckDefaultValue(
            SchemaAttDef attdef,
            SchemaInfo sinfo,
            IDtdParserAdapter readerAdapter
            )
        {
            try {
                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)
                {
                    Uri    baseUri    = readerAdapter.BaseUri;
                    string baseUriStr = (baseUri == null) ? string.Empty : baseUri.ToString();
                    if (dtype.Variety == XmlSchemaDatatypeVariety.List)
                    {
                        string[] ss = (string[])typedValue;
                        foreach (string s in ss)
                        {
                            ProcessEntity(sinfo, s, readerAdapter, readerAdapter.EventHandler, baseUriStr, attdef.ValueLineNum, attdef.ValueLinePos);
                        }
                    }
                    else
                    {
                        ProcessEntity(sinfo, (string)typedValue, readerAdapter, readerAdapter.EventHandler, baseUriStr, attdef.ValueLineNum, attdef.ValueLinePos);
                    }
                }
                else if (ttype == XmlTokenizedType.ENUMERATION)
                {
                    if (!attdef.CheckEnumeration(typedValue))
                    {
                        XmlSchemaException e = new XmlSchemaException(Res.Sch_EnumerationValue, typedValue.ToString(), readerAdapter.BaseUri.ToString(), attdef.ValueLineNum, attdef.ValueLinePos);
                        readerAdapter.SendValidationEvent(XmlSeverityType.Error, e);
                    }
                }
            }
#if DEBUG
            catch (XmlSchemaException ex) {
                Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, ex.Message);
#else
            catch (Exception)  {
#endif
                XmlSchemaException e = new XmlSchemaException(Res.Sch_AttributeDefaultDataType, attdef.Name.ToString());
                readerAdapter.SendValidationEvent(XmlSeverityType.Error, e);
            }
        }
 protected void SendValidationEvent(XmlSchemaException e, XmlSeverityType severity)
 {
     if (severity == XmlSeverityType.Error)
     {
         this.errorCount++;
     }
     if (this.eventHandler != null)
     {
         this.eventHandler(null, new ValidationEventArgs(e, severity));
     }
     else if (severity == XmlSeverityType.Error)
     {
         throw e;
     }
 }
        public static void RaiseValidationEvent(ValidationEventHandler handle, Exception innerException, string message, XmlSchemaObject xsobj, object sender, string sourceUri, XmlSeverityType severity)
        {
            XmlSchemaException  ex = new XmlSchemaException(message, sender, sourceUri, xsobj, innerException);
            ValidationEventArgs validationEventArgs = new ValidationEventArgs(ex, message, severity);

            if (handle == null)
            {
                if (validationEventArgs.Severity == XmlSeverityType.Error)
                {
                    throw validationEventArgs.Exception;
                }
            }
            else
            {
                handle(sender, validationEventArgs);
            }
        }
 public static void CheckDefaultValue(SchemaAttDef attdef, SchemaInfo sinfo, IValidationEventHandling eventHandling, string baseUriStr)
 {
     try
     {
         if (baseUriStr == null)
         {
             baseUriStr = string.Empty;
         }
         XmlSchemaDatatype datatype = attdef.Datatype;
         if (datatype != null)
         {
             object           defaultValueTyped = attdef.DefaultValueTyped;
             XmlTokenizedType tokenizedType     = datatype.TokenizedType;
             if (tokenizedType == XmlTokenizedType.ENTITY)
             {
                 if (datatype.Variety == XmlSchemaDatatypeVariety.List)
                 {
                     string[] strArray = (string[])defaultValueTyped;
                     for (int i = 0; i < strArray.Length; i++)
                     {
                         BaseValidator.ProcessEntity(sinfo, strArray[i], eventHandling, baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
                     }
                 }
                 else
                 {
                     BaseValidator.ProcessEntity(sinfo, (string)defaultValueTyped, eventHandling, baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
                 }
             }
             else if (((tokenizedType == XmlTokenizedType.ENUMERATION) && !attdef.CheckEnumeration(defaultValueTyped)) && (eventHandling != null))
             {
                 XmlSchemaException exception = new XmlSchemaException("Sch_EnumerationValue", defaultValueTyped.ToString(), baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
                 eventHandling.SendEvent(exception, XmlSeverityType.Error);
             }
         }
     }
     catch (Exception)
     {
         if (eventHandling != null)
         {
             XmlSchemaException exception2 = new XmlSchemaException("Sch_AttributeDefaultDataType", attdef.Name.ToString());
             eventHandling.SendEvent(exception2, XmlSeverityType.Error);
         }
     }
 }
 public static void CheckDefaultValue(SchemaAttDef attdef, SchemaInfo sinfo, IValidationEventHandling eventHandling, string baseUriStr)
 {
     try
     {
         if (baseUriStr == null)
         {
             baseUriStr = string.Empty;
         }
         XmlSchemaDatatype datatype = attdef.Datatype;
         if (datatype != null)
         {
             object defaultValueTyped = attdef.DefaultValueTyped;
             XmlTokenizedType tokenizedType = datatype.TokenizedType;
             if (tokenizedType == XmlTokenizedType.ENTITY)
             {
                 if (datatype.Variety == XmlSchemaDatatypeVariety.List)
                 {
                     string[] strArray = (string[]) defaultValueTyped;
                     for (int i = 0; i < strArray.Length; i++)
                     {
                         BaseValidator.ProcessEntity(sinfo, strArray[i], eventHandling, baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
                     }
                 }
                 else
                 {
                     BaseValidator.ProcessEntity(sinfo, (string) defaultValueTyped, eventHandling, baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
                 }
             }
             else if (((tokenizedType == XmlTokenizedType.ENUMERATION) && !attdef.CheckEnumeration(defaultValueTyped)) && (eventHandling != null))
             {
                 XmlSchemaException exception = new XmlSchemaException("Sch_EnumerationValue", defaultValueTyped.ToString(), baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
                 eventHandling.SendEvent(exception, XmlSeverityType.Error);
             }
         }
     }
     catch (Exception)
     {
         if (eventHandling != null)
         {
             XmlSchemaException exception2 = new XmlSchemaException("Sch_AttributeDefaultDataType", attdef.Name.ToString());
             eventHandling.SendEvent(exception2, XmlSeverityType.Error);
         }
     }
 }
 internal static string WarningDetails(XmlSchemaException exception, string message) {
     string details;
     XmlSchemaObject source = exception.SourceSchemaObject;
     if (exception.LineNumber == 0 && exception.LinePosition == 0) {
         details = GetSchemaItem(source, null, message);
     }
     else {
         string ns = null;
         if (source != null) {
             while (source.Parent != null) {
                 source = source.Parent;
             }
             if (source is XmlSchema) {
                 ns = ((XmlSchema)source).TargetNamespace;
             }
         }
         details = Res.GetString(Res.SchemaSyntaxErrorDetails, ns, message, exception.LineNumber, exception.LinePosition);
     }
     return details;
 }
Example #15
0
		public static void RaiseValidationEvent(ValidationEventHandler handle,
			Exception innerException,
			string message,
			XmlSchemaObject xsobj,
			object sender,
			string sourceUri,
			XmlSeverityType severity)
		{
			XmlSchemaException ex = new XmlSchemaException (
				message, sender, sourceUri, xsobj, innerException);
			ValidationEventArgs e = new ValidationEventArgs(ex,message,severity);
			if(handle == null)
			{
				if (e.Severity == XmlSeverityType.Error)
					throw e.Exception;
			}
			else
			{
				handle(sender,e);
			}
		}
        protected static void ProcessEntity(System.Xml.Schema.SchemaInfo sinfo, string name, object sender, ValidationEventHandler eventhandler, string baseUri, int lineNumber, int linePosition)
        {
            SchemaEntity       entity;
            XmlSchemaException ex = null;

            if (!sinfo.GeneralEntities.TryGetValue(new XmlQualifiedName(name), out entity))
            {
                ex = new XmlSchemaException("Sch_UndeclaredEntity", name, baseUri, lineNumber, linePosition);
            }
            else if (entity.NData.IsEmpty)
            {
                ex = new XmlSchemaException("Sch_UnparsedEntityRef", name, baseUri, lineNumber, linePosition);
            }
            if (ex != null)
            {
                if (eventhandler == null)
                {
                    throw ex;
                }
                eventhandler(sender, new ValidationEventArgs(ex));
            }
        }
        protected static void ProcessEntity(System.Xml.Schema.SchemaInfo sinfo, string name, IValidationEventHandling eventHandling, string baseUriStr, int lineNumber, int linePosition)
        {
            SchemaEntity entity;
            string       res = null;

            if (!sinfo.GeneralEntities.TryGetValue(new XmlQualifiedName(name), out entity))
            {
                res = "Sch_UndeclaredEntity";
            }
            else if (entity.NData.IsEmpty)
            {
                res = "Sch_UnparsedEntityRef";
            }
            if (res != null)
            {
                XmlSchemaException exception = new XmlSchemaException(res, name, baseUriStr, lineNumber, linePosition);
                if (eventHandling == null)
                {
                    throw exception;
                }
                eventHandling.SendEvent(exception, XmlSeverityType.Error);
            }
        }
Example #18
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 #19
0
        protected static void ProcessEntity(SchemaInfo sinfo, string name, IValidationEventHandling eventHandling, string baseUriStr, int lineNumber, int linePosition) {
            SchemaEntity en;
            string errorResId = null;
            if (!sinfo.GeneralEntities.TryGetValue(new XmlQualifiedName(name), out en)) {
                // validation error, see xml spec [68]
                errorResId = Res.Sch_UndeclaredEntity;

            }
            else if (en.NData.IsEmpty) {
                errorResId = Res.Sch_UnparsedEntityRef;
            }
            if (errorResId != null) {
                XmlSchemaException e = new XmlSchemaException(errorResId, name, baseUriStr, lineNumber, linePosition);

                if (eventHandling != null) {
                    eventHandling.SendEvent(e, XmlSeverityType.Error);
                }
                else {
                    throw e;
                }
            }
        }
Example #20
0
 protected void SendValidationEvent(XmlSchemaException e, XmlSeverityType severity) {
     if (eventHandling != null) {
         eventHandling.SendEvent(e, severity);
     }
     else if (severity == XmlSeverityType.Error) {
         throw e;
     }
 }
 private void SendValidationEvent( XmlSeverityType severity, XmlSchemaException e ) {
     Debug.Assert( validate );
     readerAdapter.SendValidationEvent( severity, e );
 }
 internal XmlSchemaException(string message, int lineNumber, int linePosition, XmlSchemaObject sourceObject, string sourceUri, Exception innerException) : base(XmlSchemaException.GetMessage(message, sourceUri, lineNumber, linePosition, sourceObject), innerException)
 {
     this.hasLineInfo  = true;
     this.lineNumber   = lineNumber;
     this.linePosition = linePosition;
     this.sourceObj    = sourceObject;
     this.sourceUri    = sourceUri;
 }
        internal XmlSchemaException(string message, object sender, string sourceUri, XmlSchemaObject sourceObject, Exception innerException) : base(XmlSchemaException.GetMessage(message, sourceUri, sender, sourceObject), innerException)
        {
            IXmlLineInfo xmlLineInfo = sender as IXmlLineInfo;

            if (xmlLineInfo != null && xmlLineInfo.HasLineInfo())
            {
                this.hasLineInfo  = true;
                this.lineNumber   = xmlLineInfo.LineNumber;
                this.linePosition = xmlLineInfo.LinePosition;
            }
            this.sourceObj = sourceObject;
        }
Example #24
0
 private void SendValidationEvent(XmlSchemaException e, XmlSeverityType severity) {
     this.schema.ErrorCount++;
     e.SetSchemaObject(this.schema);
     if (validationEventHandler != null) {
         validationEventHandler(null, new ValidationEventArgs(e, severity));
     }
     else if (severity == XmlSeverityType.Error) {
         throw e;
     }
 }
Example #25
0
 private void SendValidationEvent(XmlSeverityType severity, XmlSchemaException exception)
 {
     if (_validationEventHandling != null)
     {
         _validationEventHandling.SendEvent(exception, severity);
     }
 }
        /// <summary>
        /// Handles a XmlValidation exception/error
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="arguments"></param>
        private static void ValidationError(object sender, ValidationEventArgs arguments)
        {
            m_SchemaException = arguments.Exception;
            m_sValidationErrorMessage = arguments.Message;
            m_SeverityType = arguments.Severity;

            m_bXmlFileValid = false;
        }
        /// <summary>
        /// Handles a Schema read exception/error
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="arguments"></param>
        private static void SchemaReadError(object sender, ValidationEventArgs arguments)
        {
            m_SchemaException = arguments.Exception;
            m_sValidationErrorMessage = arguments.Message;
            m_SeverityType = arguments.Severity;

            throw new Exception("SchemaReadError: " + arguments.Message);
        }
 internal XmlSchemaException(string message, XmlSchemaObject sourceObject, Exception innerException) : base(XmlSchemaException.GetMessage(message, null, 0, 0, sourceObject), innerException)
 {
     this.hasLineInfo = true;
 }
 /// <summary>Initializes a new instance of the <see cref="T:System.Xml.Schema.XmlSchemaException" /> class with the exception message and original <see cref="T:System.Exception" /> object that caused this exception specified.</summary>
 /// <param name="message">A string description of the error condition.</param>
 /// <param name="innerException">The original T:System.Exception object that caused this exception.</param>
 public XmlSchemaException(string message, Exception innerException) : base(XmlSchemaException.GetMessage(message, null, 0, 0, null), innerException)
 {
 }
Example #30
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 #31
0
		public void PermitOnlySerializationFormatter_GetObjectData ()
		{
			StreamingContext sc = new StreamingContext (StreamingContextStates.All);
			XmlSchemaException xe = new XmlSchemaException (String.Empty, null);
			xe.GetObjectData (null, sc);
		}
Example #32
0
 private void SendValidationEvent(XmlSeverityType severity, XmlSchemaException e)
 {
     Debug.Assert(_validate);
     IValidationEventHandling eventHandling = _readerAdapterWithValidation.ValidationEventHandling;
     if (eventHandling != null)
     {
         eventHandling.SendEvent(e, severity);
     }
 }
Example #33
0
 internal ValidationEventArgs(XmlSchemaException ex, string message, XmlSeverityType severity)
 {
     this.exception = ex;
     this.message   = message;
     this.severity  = severity;
 }
        internal override Exception TryParseValue(object value, XmlNameTable nameTable, IXmlNamespaceResolver nsmgr, out object typedValue) {
            Exception exception;
            if (value == null) {
                throw new ArgumentNullException("value");
            }
            typedValue = null;
            string s = value as string;
            if (s != null) {
                return TryParseValue(s, nameTable, nsmgr, out typedValue);
            }

            object valueToCheck = null;
            XmlSchemaSimpleType memberType = null;
            for (int i = 0; i < types.Length; ++i) {
                if (types[i].Datatype.TryParseValue(value, nameTable, nsmgr, out valueToCheck) == null) { //no error
                    memberType = types[i];
                    break;
                }
            }
            if (valueToCheck == null) {
                exception = new XmlSchemaException(Res.Sch_UnionFailedEx, value.ToString());
                goto Error;
            }
            try {
                if (this.HasLexicalFacets) {
                    string s1 = (string)this.ValueConverter.ChangeType(valueToCheck, typeof(System.String), nsmgr); //Using value here to avoid info loss
                    exception = unionFacetsChecker.CheckLexicalFacets(ref s1, this);
                    if (exception != null) goto Error;
                }
                typedValue = new XsdSimpleValue(memberType, valueToCheck);
                if (this.HasValueFacets) {
                    exception = unionFacetsChecker.CheckValueFacets(typedValue, this);
                    if (exception != null) goto Error;
                }
                return null;
            }
            catch (FormatException e) { //Catching for exceptions thrown by ValueConverter
                exception = e;
            }
            catch (InvalidCastException e) { //Catching for exceptions thrown by ValueConverter
                exception = e;
            }
            catch (OverflowException e) { //Catching for exceptions thrown by ValueConverter
                exception = e;
            }
            catch (ArgumentException e) { //Catching for exceptions thrown by ValueConverter
                exception = e;
            }

        Error:
            return exception;
        }
        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(Res.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(Res.Sch_AttributeDefaultDataType, attdef.Name.ToString(), baseUri, lineNo, linePos);
                if (eventhandler != null) {
                    eventhandler(sender, new ValidationEventArgs(e));
                }
                else {
                    throw e;
                }
            }
        }
		private void HandleError (string message, XmlSeverityType severity)
		{
			if (validatingReader != null &&
				validatingReader.ValidationType == ValidationType.None)
				return;

			IXmlLineInfo info = this as IXmlLineInfo;
			bool hasLine = info.HasLineInfo ();
			XmlSchemaException ex = new XmlSchemaException (
				message,
				hasLine ? info.LineNumber : 0,
				hasLine ? info.LinePosition : 0, 
				null,
				BaseURI, 
				null);
			HandleError (ex, severity);
		}
 private void SendValidationEvent(XmlSchemaException e) {
     if (validationEventHandler != null) {
         validationEventHandler(this, new ValidationEventArgs(e));
     } 
     else {
         throw e;
     }
 }
Example #38
0
 internal ValidationEventArgs(XmlSchemaException ex)
 {
     this.ex       = ex;
     this.severity = XmlSeverityType.Error;
 }
Example #39
0
 protected static void ProcessEntity(SchemaInfo sinfo, string name, object sender, ValidationEventHandler eventhandler, string baseUri, int lineNumber, int linePosition) {
     SchemaEntity en;
     XmlSchemaException e = null;
     if (!sinfo.GeneralEntities.TryGetValue(new XmlQualifiedName(name), out en)) {
         // validation error, see xml spec [68]
         e = new XmlSchemaException(Res.Sch_UndeclaredEntity, name, baseUri, lineNumber, linePosition);
     }
     else if (en.NData.IsEmpty) {
         e = new XmlSchemaException(Res.Sch_UnparsedEntityRef, name, baseUri, lineNumber, linePosition);
     }
     if (e != null) {
         if (eventhandler != null) {
             eventhandler(sender, new ValidationEventArgs(e));
         }
         else {
             throw e;
         }
     }
 }
Example #40
0
        internal static void CheckDefaultValue(
            string              value,
            SchemaAttDef        attdef,
            SchemaInfo          sinfo,
            XmlNamespaceManager     nsManager,
            XmlNameTable        nameTable,
            object              sender,
            ValidationEventHandler  eventhandler
        ) {
#if DEBUG
            Debug.WriteLineIf(CompModSwitches.XmlSchema.TraceVerbose, string.Format("Validator.CheckDefaultValue(\"{0}\")", value));
#endif
            try {

                XmlSchemaDatatype dtype = attdef.Datatype;
                if (dtype == null) {
                    return; // no reason to check
                }
                if (sinfo.SchemaType != SchemaType.XSD) {
                    if (dtype.TokenizedType != XmlTokenizedType.CDATA) {
                        value = value.Trim();
                    }
                    if (sinfo.SchemaType == SchemaType.XDR && value == string.Empty) {
                        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;
                        foreach(string s in ss) {
                            ProcessEntity(sinfo, s, sender, eventhandler);
                        }
                    }
                    else {
                        ProcessEntity(sinfo, (string)typedValue, sender, eventhandler);
                    }
                }
                else if (ttype == XmlTokenizedType.ENUMERATION) {
                    if (!attdef.CheckEnumeration(typedValue)) {
                        XmlSchemaException e = new XmlSchemaException(Res.Sch_EnumerationValue, typedValue.ToString());
                        if (eventhandler != null) {
                            eventhandler(sender, new ValidationEventArgs(e));
                        }
                        else {
                            throw e;
                        }
                    }
                }
                attdef.DefaultValueTyped = typedValue;
            }
#if DEBUG
            catch (XmlSchemaException ex) {
                Debug.WriteLineIf(CompModSwitches.XmlSchema.TraceError, ex.Message);
#else
            catch  {
#endif
                XmlSchemaException e = new XmlSchemaException(Res.Sch_AttributeDefaultDataType, attdef.Name.ToString());
                if (eventhandler != null) {
                    eventhandler(sender, new ValidationEventArgs(e));
                }
                else {
                    throw e;
                }
            }
        }
 private void SendValidationEvent(XmlSchemaException e)
 {
     this.SendValidationEvent(new XmlSchemaValidationException(e.GetRes, e.Args, e.SourceUri, e.LineNumber, e.LinePosition), XmlSeverityType.Error);
 }
Example #42
0
 private void SendValidationEvent(XmlSchemaException e, XmlSeverityType severity) {
     if (validationEventHandler != null) {
         validationEventHandler(null, new ValidationEventArgs(e, severity));
     }
     else if (severity == XmlSeverityType.Error) {
         throw e;
     }
 }
Example #43
0
 private void SendValidationEvent(XmlSchemaException e, XmlSeverityType severity)
 {
     _SchemaInfo.ErrorCount++;
     if (_validationEventHandler != null)
     {
         _validationEventHandler(this, new ValidationEventArgs(e, severity));
     }
     else if (severity == XmlSeverityType.Error)
     {
         throw e;
     }
 }
 internal void DtdParserProxy_SendValidationEvent( XmlSeverityType severity, XmlSchemaException exception ) {
     if ( DtdValidation ) {
         this.SendValidationEvent( severity, exception );
     }
 }
Example #45
0
 private void SendValidationEvent(XmlSchemaException e) {
     SendValidationEvent(e, XmlSeverityType.Error);
 }
 void SendValidationEvent( XmlSeverityType severity, XmlSchemaException exception ) {
     if ( validationEventHandler != null ) {
         validationEventHandler( this, new ValidationEventArgs( exception, severity ) );
     }
 }
        internal override Exception TryParseValue(string s, XmlNameTable nameTable, IXmlNamespaceResolver nsmgr, out object typedValue) {
            Exception exception;
            XmlSchemaSimpleType memberType = null;

            typedValue = null;

            exception = unionFacetsChecker.CheckLexicalFacets(ref s, this);
            if (exception != null) goto Error;

            //Parse string to CLR value
            for (int i = 0; i < types.Length; ++i) {
                exception = types[i].Datatype.TryParseValue(s, nameTable, nsmgr, out typedValue);
                if (exception == null) {
                    memberType = types[i];
                    break;
                }
            }
            if (memberType == null) {
                exception = new XmlSchemaException(Res.Sch_UnionFailedEx, s);
                goto Error;
            }

            typedValue = new XsdSimpleValue(memberType, typedValue);
            exception = unionFacetsChecker.CheckValueFacets(typedValue, this);
            if (exception != null) goto Error;

            return null;

        Error:
            return exception;
        }
 public static void SetDefaultTypedValue(SchemaAttDef attdef, IDtdParserAdapter readerAdapter)
 {
     try
     {
         string defaultValueExpanded = attdef.DefaultValueExpanded;
         XmlSchemaDatatype datatype = attdef.Datatype;
         if (datatype != null)
         {
             if (datatype.TokenizedType != XmlTokenizedType.CDATA)
             {
                 defaultValueExpanded = defaultValueExpanded.Trim();
             }
             attdef.DefaultValueTyped = datatype.ParseValue(defaultValueExpanded, readerAdapter.NameTable, readerAdapter.NamespaceResolver);
         }
     }
     catch (Exception)
     {
         IValidationEventHandling validationEventHandling = ((IDtdParserAdapterWithValidation) readerAdapter).ValidationEventHandling;
         if (validationEventHandling != null)
         {
             XmlSchemaException exception = new XmlSchemaException("Sch_AttributeDefaultDataType", attdef.Name.ToString());
             validationEventHandling.SendEvent(exception, XmlSeverityType.Error);
         }
     }
 }
Example #49
0
 protected void SendValidationEvent(XmlSchemaException e)
 {
     SendValidationEvent(e, XmlSeverityType.Error);
 }
 private string FormatPosition(XmlSchemaException xmlSchemaException)
 {
     return string.Format(" @ line:{0} column:{1}", xmlSchemaException.LineNumber, xmlSchemaException.LinePosition);
 }
		private void HandleError (XmlSchemaException ex, XmlSeverityType severity)
		{
			if (validatingReader != null &&
				validatingReader.ValidationType == ValidationType.None)
				return;

			if (validatingReader != null)
				this.validatingReader.OnValidationEvent (this,
					new ValidationEventArgs (ex, ex.Message, severity));
			else if (severity == XmlSeverityType.Error)
				throw ex;
		}
Example #52
0
 internal ValidationEventArgs(XmlSchemaException ex, XmlSeverityType severity)
 {
     this.ex       = ex;
     this.severity = severity;
 }