Class XmlValidationError
- All Implemented Interfaces:
Serializable
XmlError
XMLError class. The XML Validator contains
extra attributes that can be used to construct the XML validation error programmatically.
To extract the validation error cast the errors to XmlValidationError instead of
XmlError for example:
xobj.validate(new XmlOptions().setErrorListener(errors)) for (Iterator<XmlError> it = errors.iterator(); it.hasNext(); ) { XmlError err = it.next()); if (err instanceof XmlValidationError) { XmlValidationError validationError = (XmlValidationError) err; } }Whenever an XmlValidationError is retrieved it will always be populated with the following information:
- Message
- Severity
- Error Type
The error type is very important because the other attributes of the XMLValidationError are populated based on the error type.
if errortype == INCORRECT_ELEMENT thenoffendingQName, badSchemaType will always be present, however expectedSchemaType and expectedQNames are available only if it is possible to determine them during vaildation.
if errortype == ELEMENT_NOT_ALLOWED then
badSchemaType will always be present, however expectedSchemaType and
offendingQName are available only if it is possible to determine them during vaildation.
if errortype == INCORRECT_ATTRIBUTE then
offendingQName, badSchemaType will always be present
if errortype == ATTRIBUTE_TYPE_INVALID then
no other addtional attributes are populated
if errortype == LIST_INVALID then
expectedSchemaType will always be present
if errortype == UNION_INVALID then
expectedSchemaType will always be present
if errortype == NIL_ELEMENT then
offendingQName, expectedSchemaType and badSchemaType will always be present
if errortype == ELEMENT_TYPE_INVALID then
offendingQName will always be present, other attributes may be available
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
Fields inherited from class org.apache.xmlbeans.XmlError
SEVERITY_ERROR, SEVERITY_INFO, SEVERITY_WARNING
-
Method Summary
Modifier and TypeMethodDescriptionstatic XmlValidationError
forCursorWithDetails
(String message, String code, Object[] args, int severity, XmlCursor cursor, QName fieldQName, QName offendingQname, SchemaType expectedSchemaType, List<QName> expectedQNames, int errorType, SchemaType badSchemaType) static XmlValidationError
forLocationWithDetails
(String message, String code, Object[] args, int severity, Location location, QName fieldQName, QName offendingQname, SchemaType expectedSchemaType, List<QName> expectedQNames, int errorType, SchemaType badSchemaType) int
Returns the error message without location information.void
setBadSchemaType
(SchemaType _badSchemaType) void
setErrorType
(int _errorType) void
setExpectedQNames
(List<QName> _expectedQNames) void
setExpectedSchemaType
(SchemaType _expectedSchemaType) void
setFieldQName
(QName _fieldQName) void
setOffendingQName
(QName _offendingQName) Methods inherited from class org.apache.xmlbeans.XmlError
forCursor, forCursor, forCursor, forCursor, forLocation, forLocation, forLocation, forLocation, forLocationAndCursor, formattedMessage, forMessage, forMessage, forMessage, forMessage, forObject, forObject, forObject, forObject, forSource, forSource, forSource, getColumn, getCursorLocation, getErrorCode, getLine, getLocation, getObjectLocation, getOffset, getSeverity, getSourceName, severityAsString, toString, toString
-
Field Details
-
INCORRECT_ELEMENT
public static final int INCORRECT_ELEMENT- See Also:
-
ELEMENT_NOT_ALLOWED
public static final int ELEMENT_NOT_ALLOWED- See Also:
-
ELEMENT_TYPE_INVALID
public static final int ELEMENT_TYPE_INVALID- See Also:
-
NIL_ELEMENT
public static final int NIL_ELEMENT- See Also:
-
INCORRECT_ATTRIBUTE
public static final int INCORRECT_ATTRIBUTE- See Also:
-
ATTRIBUTE_TYPE_INVALID
public static final int ATTRIBUTE_TYPE_INVALID- See Also:
-
LIST_INVALID
public static final int LIST_INVALID- See Also:
-
UNION_INVALID
public static final int UNION_INVALID- See Also:
-
UNDEFINED
public static final int UNDEFINED- See Also:
-
-
Method Details
-
forCursorWithDetails
public static XmlValidationError forCursorWithDetails(String message, String code, Object[] args, int severity, XmlCursor cursor, QName fieldQName, QName offendingQname, SchemaType expectedSchemaType, List<QName> expectedQNames, int errorType, SchemaType badSchemaType) -
forLocationWithDetails
public static XmlValidationError forLocationWithDetails(String message, String code, Object[] args, int severity, Location location, QName fieldQName, QName offendingQname, SchemaType expectedSchemaType, List<QName> expectedQNames, int errorType, SchemaType badSchemaType) -
getMessage
Description copied from class:XmlError
Returns the error message without location information.- Overrides:
getMessage
in classXmlError
-
getBadSchemaType
-
setBadSchemaType
-
getErrorType
public int getErrorType() -
setErrorType
public void setErrorType(int _errorType) -
getExpectedQNames
-
setExpectedQNames
-
getFieldQName
-
setFieldQName
-
getOffendingQName
-
setOffendingQName
-
getExpectedSchemaType
-
setExpectedSchemaType
-