Validation Event Handler is associated with an event exposed by Xml Validating Reader that also is named Validation Event Handler.The Validation Event Handler delegate has this signature: public delegate void Validation Event Handler( object sender, Validation Event Args e); The Validation Event Args parameter has Exception, Message, and Severity properties you can use to access detailed error information.
Figure 1 provides an overview of the functionality the Xml Import Service application provides. The Xml Import Service watches for XML documents in a "drop" directory, then validates and parses them.Any validation errors that occur while the XML document is validated cause the Validation Call Back method to be called.If an error-log file path is passed into Validate Xml, the error details will be written to the file by Validation Call Back. private void Validation Call Back(object sender, Validation Event Args args) Figure 3.You can find a complete listing of the Xml Validating Reader's different properties and methods in the . Figure 2 contains the shell for the custom Xml Validator class.Notice that it contains several different fields used to track data during the validation process; it also contains methods named Validate Xml and Validation Call Back. You can validate XML documents against DTDs or schemas by using the Xml Validator class's Xml Validating Reader class.By Dan Wahlin Validating XML is important any time the structure or data contained within an XML document must follow a predefined format for an application to use it.
You can use several different formats to validate XML documents, including Document Type Definitions (DTDs), XML Data Reduced (XDR) schemas, and W3C XML (XSD) schemas. NET Framework provides support for each of these formats, XML schemas arguably provide the greatest power and flexibility in validating XML.
This method accepts an object representing either the path to the XML document or the XML document loaded into a String Reader object; an Xml Schema Collection object containing one or more schemas used to validate the XML document; a string array containing any needed DTD information; and the path to the error-log file.
Validate Xml returns a struct named Validation Status, which contains the status of the validation operation: public struct Validation Status The Validation Status struct contains two public fields: Status and Error Messages.
This task is accomplished using the File System Watcher class in the System. Once an XML file is detected in the watch folder, it needs to be validated using the Xml Validator class I'll describe in this article.
If the document passes the validation process, it will be parsed using the Xml Text Reader, and SQL insert statements will be generated to insert rows into the Northwind Database's Customers table.
I'll discuss the code that goes within the different methods later in this article.