Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ValidationProgram
- {
- public class testException : MyException
- {
- public override string Message
- {
- get
- {
- return "data type is incorrect";
- }
- }
- }
- }
- namespace ValidationProgram
- {
- [Serializable]
- public class MyException : Exception
- {
- public MyException() { }
- public MyException(string message) : base(message) { }
- public MyException(string message, Exception inner) : base(message, inner) { }
- protected MyException(
- System.Runtime.Serialization.SerializationInfo info,
- System.Runtime.Serialization.StreamingContext context)
- : base(info, context) { }
- }
- }
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- }
- private void Validator_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- //Validating Order
- XmlReaderSettings settings = new XmlReaderSettings();
- settings.Schemas.Add("OrderValidator.xsd");
- settings.ValidationType = ValidationType.Schema;
- XmlReader order = XmlReader.Create("order.xml", settings);
- XmlDocument xdoc = new XmlDocument();
- xdoc.Load(order);
- ValidationEventHandler handler = new ValidationEventHandler(ValidationEventHandler);
- xdoc.Validate(handler);
- }
- catch (MyException ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- private void ValidationEventHandler(object sender, ValidationEventArgs e)
- {
- throw new testException();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement