Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. namespace ValidationProgram
  2. {
  3. public class testException : MyException
  4. {
  5. public override string Message
  6. {
  7. get
  8. {
  9. return "data type is incorrect";
  10. }
  11. }
  12. }
  13. }
  14.  
  15.  
  16. namespace ValidationProgram
  17. {
  18. [Serializable]
  19. public class MyException : Exception
  20. {
  21. public MyException() { }
  22. public MyException(string message) : base(message) { }
  23. public MyException(string message, Exception inner) : base(message, inner) { }
  24. protected MyException(
  25. System.Runtime.Serialization.SerializationInfo info,
  26. System.Runtime.Serialization.StreamingContext context)
  27. : base(info, context) { }
  28. }
  29.  
  30. }
  31.  
  32.  
  33.  
  34. public partial class MainWindow : Window
  35. {
  36. public MainWindow()
  37. {
  38. InitializeComponent();
  39. }
  40.  
  41. private void Validator_Click(object sender, RoutedEventArgs e)
  42. {
  43.  
  44.  
  45.  
  46. try
  47. {
  48.  
  49.  
  50. //Validating Order
  51.  
  52. XmlReaderSettings settings = new XmlReaderSettings();
  53. settings.Schemas.Add("OrderValidator.xsd");
  54. settings.ValidationType = ValidationType.Schema;
  55.  
  56.  
  57. XmlReader order = XmlReader.Create("order.xml", settings);
  58. XmlDocument xdoc = new XmlDocument();
  59. xdoc.Load(order);
  60.  
  61. ValidationEventHandler handler = new ValidationEventHandler(ValidationEventHandler);
  62.  
  63. xdoc.Validate(handler);
  64.  
  65.  
  66. }
  67.  
  68.  
  69. catch (MyException ex)
  70. {
  71. MessageBox.Show(ex.Message);
  72. }
  73. }
  74.  
  75. private void ValidationEventHandler(object sender, ValidationEventArgs e)
  76. {
  77. throw new testException();
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement