Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
HydraExpress XML Binding Development Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

2.4 Validation

HydraExpress provides warnings at code generation time for errors and unsupported features in a schema document. At run time, HydraExpress provides structural validation of the instance document and provides support for simple type validation.

2.4.1 Schema Document Validation

At code generation time, HydraExpress provides validation of the input schema through the Xerces Schema parser. Any error messages are passed directly to the standard output. Note that the Xerces parser expects the top-level schema element to have a schemaLocation attribute, and reports an error if one is not present.

Whatever the results of the validation, HydraExpress attempts to compile any well-formed XML Schema document, whether or not that document is a valid XML Schema. That is, the compiler treats warnings as diagnostic messages rather than errors. HydraExpress processes as much of the schema as possible, regardless of warnings. Therefore, providing an invalid schema may result in classes that do not compile.

2.4.2 Instance Document Validation

The purpose of an XML Schema is to define a set of constraints on the XML markup. Validation is the process of determining whether a document conforms to a specific set of constraints.

For an instance document, HydraExpress distinguishes three levels of validation. The lowest level of validation is that a document be well-formed.

At runtime, HydraExpress provides structural validation when marshaling or unmarshaling a document.

When unmarshaling a document into an object, the unmarshal method throws an exception when the XML document is incorrect. The function ignores minor defects. For example, the method silently ignores attributes not mentioned in the schema, but throws an exception if a required attribute is not present.

When marshaling an XML document from an object, the marshal function produces a structurally valid XML document. If the data in the object conforms to the schema, HydraExpress produces a schema valid document.

Each class that HydraExpress generates contains an isValid() method. This method can be used to validate simple type data associated with the class. Currently isValid() validates all simple type data; however, for patterns and enumerations, the method validates only string types. In addition, isValid() checks user defined facets, but not the data's string base type.

The isValid() method returns a bool value of true if no errors are detected, or false if any data values are found to violate restrictions or facets expressed in the schema. For a return value of false, the errors are stored in a Standard C++ Library vector of rwsf::XmlSchemaException objects. If you use the overload of isValid() that passes in an rwsf::XmlValidator instance, you can use the validator's getErrors() method to obtain the vector object, then iterate through the vector to obtain information on the errors. rwsf::XmlSchemaException inherits from rwsf::Exception, so you can use the what() method to obtain the string that describes the error. For an example of how to check for errors when using isValid(), see Section 3.6.3, "Validating the Instance Document."



Previous fileTop of DocumentContentsIndex pageNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo are registered trademarks of Rogue Wave Software, and HydraExpress is a trademark of Rogue Wave Software. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.