Net xmlvalidatingreader example
NET applications, you use the Xml Text Reader class to parse XML documents. NET Framework provides full XML Document Object Model (DOM) support and Simple API for XML (SAX) classes, XML readers and writers present an excellent balance of execution speed, memory footprint, productivity, and ease of use for XML developers. NET Framework, you implement XML DOM classes on top of readers.But the Xml Text Reader class doesn't do data validation. To gain more speed while parsing, XML readers don't provide for data validation.
After you determine the application's behavior and all its constituent modules, you can optimize the application's performance by dropping the code that validates data because you don't need to continuously validate the format of data that survived the test cycle.Dropping validation code is a common practice that isn't much different from removing debug information when you're ready to ship any Windows application.But when you develop XML applications, some exceptions make data validation necessary every time a piece of code is called to action.You need data validation, for example, when you process incoming data whose origin isn't certified or whose content layout isn't completely predictable (i.e., cases in which the text that users type at runtime determines the XML data layout). NET, you must use the Xml Validating Reader class, which derives from the Xml Text Reader class and works in much the same way.Unlike the parent class, Xml Validating Reader lets you set the required validation type and the action to take in case of errors.When you call the Xml Validating Reader's Read method, the method—in addition to jumping from one node to the next—checks the structure of the node and the node's attributes against the specified validation type.
You usually create an instance of the Xml Validating Reader class from a valid instance of an Xml Reader-based class: You cannot create a validating reader directly from a filename.
By contrast, you can set the validating reader to validate only an XML string fragment that includes certain types of nodes in a certain parsing context.
After you've obtained a running instance of Xml Validating Reader, you use it just as you would its parent class.
The following code shows how you can configure the object to automatically detect the validation type required and enforce the type's rules.
The Xml Validating Reader class supports up to four validation types: Auto, XDR, Schema, and DTD.
The Validation Type enumeration collects these values.