Click here to Skip to main content
11,712,454 members (76,993 online)
Click here to Skip to main content
Add your own
alternative version

Parser Schemas– Easy and Powerful parsing of XML-based languages

, 18 Oct 2005 43.5K 454 44
An article on parsing XML files according to the specified schema.
/***********************************************************************\
 * Comnicate.CodeDom.Xml.ParserSchemas                                 *
 * Parses xml-based languages according to a user defined schema.      *
 * Copyright � 2005 Tomas Deml (as Comnicate!)                         *
 *                  tomasdeml@msn.com                                  *
 *                                                                     *
 * This library is free software; you can redistribute it and/or       *
 * modify it under the terms of the GNU Lesser General Public          *
 * License as published by the Free Software Foundation; either        *
 * version 2.1 of the License, or (at your option) any later version.  *
 *                                                                     *
 * This library is distributed in the hope that it will be useful,     *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of      *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU   *
 * Lesser General Public License for more details.                     *
\***********************************************************************/

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.XPath;
using System.Runtime.Serialization;
using System.Security.Permissions;

namespace Comnicate.CodeDom.Xml.ParserSchemas.Rules.Evaluation
{
    /// <summary>
    /// Represents the abstract parent of all validation exceptions.
    /// </summary>
    [Serializable]
    public class ValidationException : Exception
    {
        #region Fields

        // Rule
        private Rule rule;

        // Rule navigator
        private XPathNavigator evaluatedRuleNavigator;

        #endregion

        #region .ctors

        /// <summary>
        /// Initializes a new instance of the <see cref="ValidationException"/> class.
        /// </summary>
        public ValidationException() { }

        /// <summary>
        /// Initializes a new instance of the <see cref="ValidationException"/> class with a message specified.
        /// </summary>
        /// <param name="message">Message.</param>
        public ValidationException(string message) : base(message) { }

        /// <summary>
        /// Initializes a new instance of the <see cref="ValidationException"/> class with a message and exception specified.
        /// </summary>
        /// <param name="message">Message.</param>
        /// <param name="innerException">Previous exception.</param>
        public ValidationException(string message, Exception innerException) : base(message, innerException) { }

        /// <summary>
        /// Initializes a new instance of the <see cref="ValidationException"/> class with information specified.
        /// </summary>
        /// <param name="message">Message.</param>
        /// <param name="rule">Rule.</param>
        /// <param name="ruleNavigator">Rule navigator.</param>
        /// <param name="innerException">Previous exception.</param>
        public ValidationException(string message, Rule rule, XPathNavigator ruleNavigator, Exception innerException)
            : base(message, innerException)
        {
            this.rule = rule;
            this.evaluatedRuleNavigator = ruleNavigator;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ValidationException"/> class with information specified.
        /// </summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        protected ValidationException(SerializationInfo info, StreamingContext context) : base(info, context)
        {
            if (info == null) return;
            rule = (Rule)info.GetValue("rule", typeof(Rule));
        }

        #endregion

        #region Properties
        
        /// <summary>
        /// Gets the rule that caused the exception.
        /// </summary>
        public Rule Rule
        {
            get
            {
                return this.rule;
            }
        }

        /// <summary>
        /// Gets the navigator pointing to the rule markup.
        /// </summary>
        public XPathNavigator EvaluatedRuleNavigator
        {
            get
            {
                return this.evaluatedRuleNavigator;
            }
        }

        #endregion

        #region Methods

        /// <summary>
        /// Deserializes the exception eventData.
        /// </summary>
        /// <param name="info">Info.</param>
        /// <param name="context">Context.</param>
        [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            if (info == null) return;

            base.GetObjectData(info, context);
            info.AddValue("rule", rule);
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Tomas Deml
Czech Republic Czech Republic
I'm a student of the Low-voltage Electrical Engineering specialized on Computing from the Czech republic.

I'm a C# kind of guy, fan of .NET.

I've formed a programming group called 'Comnicate!'. Currently the only member of the group is myself. Wink | ;-)

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150819.1 | Last Updated 18 Oct 2005
Article Copyright 2005 by Tomas Deml
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid