Validating xml sax

30 May

[This sample application uses a feature that was first implemented in MSXML 4.0.]With MSXML 4.0 and later, validation support for SAX applications was added.

This example demonstrates that functionality by showing you how to create a simple SAX validator application in Microsoft® Visual Basic® 6.0.

In this section we shall validate the example XML document with XML schema document catalog.xsd, with the SAXParser class. Create a SAXParser object and set the validation mode of the SAXParser object to SCHEMA_VALIDATION, as shown in the following listing: Validates the complete XML document with an XML schema if the parser is able to find a schema.

If the parser is not able find a schema or if the XML document does not conform to the schema, an error is raised.

however, the import statement does not adequately inform the schema processor where to locate the actual schema.

hence, you must provide it explicitly, or provide a way to load it on the fly.

W3C_XML_SCHEMA_NS_URI); Schema schema = schema Schema(new File("myschema.xsd")); SAXParser Factory sax Factory = SAXParser Instance(); sax Schema(schema); SAXParser parser = sax SAXParser(); parser.parse("data.xml", new Default Handler() ); That isn't the behaviour I see (the parser always validates against the schema set on the factory, even if one is set in the document).

The Error Handler used for the examples is a very simple one which reports the error to and continues until the XML document has been fully parsed or until a fatal-error has been reported.The application allows the user to select an XML file and have it validated against an XSD schema file.In this example, the SAX reader parses the sample XML file (books.xml), and writes validation results as output to a textbox control on the main form for the application.Validates the XML string/file against the specified XSD string/file.XSD files are "XML Schemas" that describe the structure of a XML document.