Load an XML document, delivered using an Xml Reader.The Xml Reader is responsible for parsing the document; this method builds a tree representation of the document (in an internal Saxon format) and returns its document node.Next, add the file to the Schemas collection of the Xml Reader Settings object and invoke the static Create method of the Xml Reader object, passing in the path of the file and the Xml Reader Settings object.
If this property is set, and if schema validation is requested, then validation will fail unless the outermost element of the document has the required name.This option requires the schema-aware version of the Saxon product (Saxon-SA).So far, I've described the steps used to validate XML data with the . From here, it's a simple matter to use to validate the contents of the file (see Listing 3).Begin by declaring variables to hold the path of the XML and XSD schema files, then create an instance of the Xml Reader Settings object and associate a validation event handler callback method to it.Fourth, set Xml Reader Settings' Xsd Validate property to True.
Fifth, add an XSD schema to the Xml Reader Settings class through its Schemas property. NET Framework gave you some capable tools for validating XML data. NET Framework 2.0 augments the original capabilities significantly. NET 1.x's XML validation features, providing new classes and methods that are not only standards-compliant, but also easy to use. An XML file is usually validated for its conformance to a particular schema or a DTD.I'll show you how to take advantage of some of these features, which will translate to better-performing, more standards-compliant XML data in your applications. The XML schema file is usually an XML-Data Reduced (XDR) or XML Schema Definition (XSD) file.The Tree Model implementation to be used for the constructed document. The main reason for using the Linked Tree alternative is if updating is required (the Tiny Tree is not updateable). The resulting line numbers are accessible to applications using the extension function saxon:line-number() applied to a node. Line numbering is not available for all kinds of source: in particular, it is not available when loading from an existing Xml Document.However, failing to provide a callback function to handle validation errors results in an exception being thrown when a validation error occurs.