HydraExpress™ C++ 2020 |
HydraExpress™ C++ API Reference Guide |
Product Documentation: HydraExpress C++ Documentation Home |
Contains methods that validate XML instance documents, available through the isValid() method of generated classes. More...
#include <rwsf/core/XmlValidator.h>
Public Types | |
enum | WhiteSpace { PRESERVE, REPLACE, COLLAPSE } |
Public Member Functions | |
XmlValidator (const std::string &name) | |
void | addError (rwsf::XmlSchemaException error) |
bool | checkEnumeration (const std::string &value, const std::string &facetValue, WhiteSpace ws=PRESERVE) |
bool | checkEnumerations () |
bool | checkEnumerations (std::string enumeration, rwsf::HashSet< std::string > enumerations, WhiteSpace ws=PRESERVE) |
template<class T > | |
bool | checkFixed (const T &fixedValue, const T &candidate) |
template<class T > | |
bool | checkFractionDigits (const T &value, const std::string &facetValue, WhiteSpace=PRESERVE) |
bool | checkLength (size_t length, const std::string &facetValue) |
bool | checkLength (const std::string &value, const std::string &facetValue, WhiteSpace ws=PRESERVE) |
template<class T > | |
bool | checkMaxExclusive (const T &value, const T &facetValue, WhiteSpace=PRESERVE) |
bool | checkMaxExclusive (const rwsf::Decimal &value, const rwsf::Decimal &facetValue, WhiteSpace=PRESERVE) |
template<class T > | |
bool | checkMaxExclusive (const ConverterBase< T > &converter, const T &value, const T &facetValue, WhiteSpace) |
bool | checkMaxExclusive (const ConverterBase< rwsf::Decimal > &converter, const rwsf::Decimal &value, const rwsf::Decimal &facetValue, WhiteSpace) |
template<class T > | |
bool | checkMaxInclusive (const T &value, const T &facetValue, WhiteSpace=PRESERVE) |
bool | checkMaxInclusive (const rwsf::Decimal &value, const rwsf::Decimal &facetValue, WhiteSpace=PRESERVE) |
template<class T > | |
bool | checkMaxInclusive (const ConverterBase< T > &converter, const T &value, const T &facetValue, WhiteSpace) |
bool | checkMaxInclusive (const ConverterBase< rwsf::Decimal > &converter, const rwsf::Decimal &value, const rwsf::Decimal &facetValue, WhiteSpace) |
bool | checkMaxLength (size_t length, const std::string &facetValue) |
bool | checkMaxLength (const std::string &value, const std::string &facetValue, WhiteSpace ws=PRESERVE) |
template<class T > | |
bool | checkMinExclusive (const T &value, const T &facetValue, WhiteSpace=PRESERVE) |
bool | checkMinExclusive (const rwsf::Decimal &value, const rwsf::Decimal &facetValue, WhiteSpace=PRESERVE) |
template<class T > | |
bool | checkMinExclusive (const ConverterBase< T > &converter, const T &value, const T &facetValue, WhiteSpace) |
bool | checkMinExclusive (const ConverterBase< rwsf::Decimal > &converter, const rwsf::Decimal &value, const rwsf::Decimal &facetValue, WhiteSpace) |
template<class T > | |
bool | checkMinInclusive (const T &value, const T &facetValue, WhiteSpace=PRESERVE) |
bool | checkMinInclusive (const rwsf::Decimal &value, const rwsf::Decimal &facetValue, WhiteSpace=PRESERVE) |
template<class T > | |
bool | checkMinInclusive (const ConverterBase< T > &converter, const T &value, const T &facetValue, WhiteSpace) |
bool | checkMinInclusive (const ConverterBase< rwsf::Decimal > &converter, const rwsf::Decimal &value, const rwsf::Decimal &facetValue, WhiteSpace) |
bool | checkMinLength (size_t length, const std::string &facetValue) |
bool | checkMinLength (const std::string &value, const std::string &facetValue, WhiteSpace ws=PRESERVE) |
bool | checkPattern (const std::string &value, const std::string &facetValue, WhiteSpace ws=PRESERVE) |
bool | checkPatterns () |
bool | checkPatterns (std::string pattern, std::vector< std::string > patterns, WhiteSpace ws=PRESERVE) |
template<class T > | |
bool | checkTotalDigits (const T &value, const std::string &facetValue, WhiteSpace=PRESERVE) |
bool | checkVectorBounds (int size, int minOccurs, int maxOccurs) |
void | clear () |
std::list< rwsf::XmlSchemaException > | getErrors () |
bool | isValid () const |
bool | isValid (XmlValidator &validator) |
rwsf::XmlValidator methods are used in classes generated by the code generator to check values in instance documents, working through the isValid() method of each generated class. In generated classes, this method validates simple type data in an instance document based on facets defined in the XML schema for that document type. In an XML schema, simple types can have associated facets that restrict the allowed data values for an element or attribute of the specified type.
When isValid() is called on one of the generated datatype classes, it checks all of the simple type data in the instance document that is modeled by the class. If any data is found to be invalid, the method returns a bool
value of false
. Only if all of the data is found to be valid does the method return true
.
The methods of rwsf::XmlValidator can be used directly to validate your own XML data. Just construct an instance of rwsf::XmlValidator with the name of the type or element name. Then you can use the functions to check the XML values individually, but you must know the class well enough to know which functions to call. You must know the facets defined for simple types in the element and call rwsf::XmlValidator methods to check the data for these simple types. For example, if an element contained simple type data with a maxLength
facet, you would call checkMaxLength() on that data.
The facet checking methods set a state variable at the end of each check. If the data is found to be invalid, the state variable is set to false
and remains false
, even if additional calls are made to the method in which the data is found to be valid. (The exception to this rule are the methods for checking enumerations and patterns, as described below for checkEnumerations() and checkPatterns().) Thus the state variable indicates whether any of the checks for a particular facet found invalid data. At any point, you can call the rwsf::XmlValidator::isValid() method, which checks all state variables to determine whether any have been set to false
. If any have been, it returns false
. If all state variables are set to true
, it returns true
.
The direct use of rwsf::XmlValidator described above is, in fact, what the implementation of the isValid() method in the generated code does.
rwsf::XmlValidator initializes an std::list for rwsf::XmlSchemaException objects. A rwsf::XmlSchemaException object is added to this list whenever one of the facet checking methods reports invalid data. If a call to isValid() returns false
, you can obtain the error list through the validator's getErrors() method and iterate through the list to obtain information on the errors discovered. rwsf::XmlSchemaException inherits from rwsf::Exception, so you can use the what() method to obtain the string that describes the error.
Passed as a parameter into the various validation methods. Declares how the validation algorithm should treat any whitespace.
rwsf::XmlValidator::XmlValidator | ( | const std::string & | name | ) |
Creates an rwsf::XmlValidator instance for the class represented by name. Initializes internal data to its default values.
void rwsf::XmlValidator::addError | ( | rwsf::XmlSchemaException | error | ) |
Adds the rwsf::XmlSchemaException to the list of errors maintained by the rwsf::XmlValidator object.
bool rwsf::XmlValidator::checkEnumeration | ( | const std::string & | value, |
const std::string & | facetValue, | ||
WhiteSpace | ws = PRESERVE |
||
) |
Checks a particular enumeration value in the instance document against one of the possible values for the enumeration, given by facetValue. Returns true
if the instance value is found to be equivalent to the possible value, false
otherwise. Sets its state variable to true
if the check returns true
, and leaves the state variable set to true
even if subsequent calls return false
.
bool rwsf::XmlValidator::checkEnumerations | ( | ) |
This method is called after checkEnumeration() has been called against all of the possible values for the enumeration. It returns the value of the state variable set by the calls to checkEnumeration(). The state variable will have been set to true
if any of the calls to checkEnumeration() found a valid value.
If this method returns false
, an rwsf::XmlSchemaException object is added to the list of errors indicating that the enumeration value is invalid.
bool rwsf::XmlValidator::checkEnumerations | ( | std::string | enumeration, |
rwsf::HashSet< std::string > | enumerations, | ||
WhiteSpace | ws = PRESERVE |
||
) |
Checks all enumeration values in the instance document enumeration against their possible values given in enumerations, which is an rwsf::HashSet of enumerations to check against. Returns true
if the instance values are found to be equivalent to the possible values, false
otherwise. Sets its state variable to true
if the check returns true
, and leaves the state variable set to true
even if subsequent calls return false
.
|
inline |
Checks whether a fixed element or fixed attribute has been set correctly by an instance document. The value to check against is given as the fixedValue argument, which can be of any type, while the element or attribute in question should be given as the candidate argument,which must be of the same type as the fixedValue argument. If the two values are equal, returns true
, otherwise, false
. If the method returns false
, an error message identifying which element/attribute failed to meet the fixed constraint is added to the list of errors for the validation.
|
inline |
For simple types that can take a fractionDigits facet, checks whether the number of digits in the fractional part of the simple type value, represented by value, is equal to or less than the number specified by facetValue. If not, the state variable is set to false
, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
bool rwsf::XmlValidator::checkLength | ( | size_t | length, |
const std::string & | facetValue | ||
) |
For simple types that can take a length facet, checks whether the length specified by facetValue equals the passed-in length argument. If not, the state variable is set to false
, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
bool rwsf::XmlValidator::checkLength | ( | const std::string & | value, |
const std::string & | facetValue, | ||
WhiteSpace | ws = PRESERVE |
||
) |
For simple types that can take a length facet, checks whether the length
of the data in the simple std::string value equals the length specified by facetValue. If not, the state variable is set to false
, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
|
inline |
For simple types that can take a maxExclusive facet, checks whether the data in the simple type value, represented by value, is less than the maximum specified by facetValue. If not, the state variable is set to false
, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
|
inline |
For simple types that can take a maxExclusive facet, checks whether the data in the decimal type value, represented by value, is less than the maximum specified by facetValue. If not, the state variable is set to false
, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
|
inline |
For simple types that can take a maxExclusive facet, checks whether the data in the simple type value, represented by value, is less than the maximum specified by facetValue. If not, the state variable is set to false
, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
|
inline |
For simple types that can take a maxExclusive facet, checks whether the data in the decimal type value, represented by value, is less than the maximum specified by facetValue. If not, the state variable is set to false
, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
|
inline |
For simple types that can take a maxInclusive facet, checks whether the data in the simple type value, represented by value, is less than or equal to the maximum specified by facetValue. If not, the state variable is set to false
, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
|
inline |
For simple types that can take a maxInclusive facet, checks whether the data in the decimal type value, represented by value, is less than or equal to the maximum specified by facetValue. If not, the state variable is set to false
, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
|
inline |
For simple types that can take a maxInclusive facet, checks whether the data in the simple type value, represented by value, is less than or equal to the maximum specified by facetValue. If not, the state variable is set to false
, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
|
inline |
For simple types that can take a maxInclusive facet, checks whether the data in the decimal type value, represented by value, is less than or equal to the maximum specified by facetValue. If not, the state variable is set to false
, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
bool rwsf::XmlValidator::checkMaxLength | ( | size_t | length, |
const std::string & | facetValue | ||
) |
For simple types that can take a maxLength facet, checks whether the length specified in the length argument is less than or equal to the maximum specified by facetValue. If not, the state variable is set to false
, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
The interpretation of the maxLength facet value depends on the simple type for which the facet is specified. See the XML Schema specification at http://www.w3.org/TR/xmlschema-0/ for details.
bool rwsf::XmlValidator::checkMaxLength | ( | const std::string & | value, |
const std::string & | facetValue, | ||
WhiteSpace | ws = PRESERVE |
||
) |
For simple types that can take a maxLength facet, checks whether the length
of the data in the simple std::string value, is less than or equal to the maximum specified by facetValue. If not, the state variable is set to false
, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
The interpretation of the maxLength facet value depends on the simple type for which the facet is specified. See the XML Schema specification at http://www.w3.org/TR/xmlschema-0/ for details.
|
inline |
For simple types that can take a minExclusive facet, checks whether the data in the simple type value, represented by value, is greater than the minimum specified by facetValue. If not, the state variable is set to false
, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
|
inline |
For simple types that can take a minExclusive facet, checks whether the data in the decimal type value, represented by value, is greater than the minimum specified by facetValue. If not, the state variable is set to false
, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
|
inline |
For simple types that can take a minExclusive facet, checks whether the data in the simple type value, represented by value, is greater than the minimum specified by facetValue. If not, the state variable is set to false
, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
|
inline |
For simple types that can take a minExclusive facet, checks whether the data in the decimal type value, represented by value, is greater than the minimum specified by facetValue. If not, the state variable is set to false
, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
|
inline |
For simple types that can take a minInclusive facet, checks whether the data in the simple type value, represented by value, is greater than or equal to the minimum specified by facetValue. If not, the state variable is set to false
, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
|
inline |
For simple types that can take a minInclusive facet, checks whether the data in the decimal type value, represented by value, is greater than or equal to the minimum specified by facetValue. If not, the state variable is set to false
, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
|
inline |
For simple types that can take a minInclusive facet, checks whether the data in the simple type value, represented by value, is greater than or equal to the minimum specified by facetValue. If not, the state variable is set to false
, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
|
inline |
For decimal types that can take a minInclusive facet, checks whether the data in the decimal type value, represented by value, is greater than or equal to the minimum specified by facetValue. If not, the state variable is set to false
, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
bool rwsf::XmlValidator::checkMinLength | ( | size_t | length, |
const std::string & | facetValue | ||
) |
For simple types that can take a minLength facet, checks whether the length specified in the length argument is greater than or equal to the minimum specified by facetValue. If not, the state variable is set to false
, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
The interpretation of the minLength facet value depends on the simple type for which the facet is specified. See the XML Schema specification at http://www.w3.org/TR/xmlschema-0/ for details.
bool rwsf::XmlValidator::checkMinLength | ( | const std::string & | value, |
const std::string & | facetValue, | ||
WhiteSpace | ws = PRESERVE |
||
) |
For simple types that can take a minLength facet, checks whether the length
of the data in the simple std::string value is greater than or equal to the minimum specified by facetValue. If not, the state variable is set to false
, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
The interpretation of the minLength facet value depends on the simple type for which the facet is specified. See the XML Schema specification at http://www.w3.org/TR/xmlschema-0/ for details.
bool rwsf::XmlValidator::checkPattern | ( | const std::string & | value, |
const std::string & | facetValue, | ||
WhiteSpace | ws = PRESERVE |
||
) |
Checks the string represented by value against a regular expression pattern represented by facetValue. Returns true
if the instance value is found to match the regular expression, false
otherwise.
Because a simple type can have two or more valid patterns defined, this method behaves similarly to checkEnumerations(). The method sets its state variable to true
if the check returns true
, and leaves the state variable set to true
even if subsequent calls return false
.
bool rwsf::XmlValidator::checkPatterns | ( | ) |
This method is called after checkPattern() has been called against all of the valid patterns defined for the simple type. It returns the value of the state variable set by the calls to checkPattern(). The state variable will have been set to true
if any of the calls to checkPattern() found a match with the defined pattern.
If this method returns false
, an rwsf::XmlSchemaException object is added to the list of errors indicating that no matches were found to defined patterns.
bool rwsf::XmlValidator::checkPatterns | ( | std::string | pattern, |
std::vector< std::string > | patterns, | ||
WhiteSpace | ws = PRESERVE |
||
) |
Checks all pattern values in an instance document against their possible values. This method is passed a vector of patterns, and then tests them all at once. Returns true
if the instance values are found to be equivalent to the possible values, false
otherwise. Sets its state variable to true
if the check returns true
.
If this method returns false
, an rwsf::XmlSchemaException object is added to the list of errors indicating that no matches were found to defined patterns.
|
inline |
For simple types that can take a totalDigits facet, checks whether the number of digits in the simple type value, represented by value, is equal to or less than the number specified by facetValue. If not, the state variable is set to false
, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
bool rwsf::XmlValidator::checkVectorBounds | ( | int | size, |
int | minOccurs, | ||
int | maxOccurs | ||
) |
If the minOccurs
and maxOccurs
attributes on an element allow the instance document to have two or more such elements in a given context, checks that the number of occurrences specified in size falls within the allowable number as specified by minOccurs and maxOccurs. If not, the state variable is set to false
, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
void rwsf::XmlValidator::clear | ( | ) |
Resets all internal data to its initial value, and clears the list that holds reported errors.
std::list<rwsf::XmlSchemaException> rwsf::XmlValidator::getErrors | ( | ) |
Returns the list that contains all reported errors. If isValid() returns false
, you can then iterate through the list to determine the nature of the errors found.
bool rwsf::XmlValidator::isValid | ( | ) | const |
Checks all of the state variables for the individual facet checks. If all state variables are set to true
, returns true
; if one or more of the state variables is set to false
, returns false
.
If the method returns false
, this validator's getErrors() method can be used to retrieve the list that holds rwsf::XmlSchemaException instances describing the errors found.
bool rwsf::XmlValidator::isValid | ( | XmlValidator & | validator | ) |
Checks all of the state variables for the rwsf::XmlValidator instance represented by validator. If all of the state variables are set to true
, returns true
; if one or more of the state variables is set to false
, returns false
.
If the method returns false
, the supplied validator's getErrors() method can be used to retrieve the list that holds rwsf::XmlSchemaException instances describing the errors found.
Copyright © 2020 Rogue Wave Software, Inc. All Rights Reserved. |