# Class SchemaValidator

java.lang.Object
org.xml.sax.helpers.DefaultHandler
ml.options.SchemaValidator

All Implemented Interfaces:
  `ContentHandler, DTDHandler, EntityResolver, ErrorHandler`

public class SchemaValidator extends DefaultHandler
Validator for XML documents using XML schema. This is based on JDK 5.0 and requires no outside library.

## Constructor Summary

Constructors
Constructor
Description
`SchemaValidator()`

## Method Summary

Modifier and Type
Method
Description
`void`
`error(SAXParseException ex)`
A method required by the `org.xml.sax.ErrorHandler` interface
`void`
`fatalError(SAXParseException ex)`
A method required by the `org.xml.sax.ErrorHandler` interface
`String`
`getError()`
Retrieve the error message set by the `org.xml.sax.ErrorHandler` methods.
`boolean`
`validate(Reader xmlReader)`
The actual validation method.
`void`
`warning(SAXParseException ex)`
A method required by the `org.xml.sax.ErrorHandler` interface

### Methods inherited from class DefaultHandler

`characters, endDocument, endElement, endPrefixMapping, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startElement, startPrefixMapping, unparsedEntityDecl`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface ContentHandler

`declaration`

## Constructor Details

### SchemaValidator

public SchemaValidator()

## Method Details

### validate

public boolean validate(Reader xmlReader) throws IOException, SAXException
The actual validation method. If validation is not successful, the errors found can be retrieved using the `getError()` method.

Parameters:
  `xmlReader` - The reader for the XML file to validate

Returns:
  `true` if the XML file could be validated against the XML schema, else `false`
Throws:
  `IOException`
  `SAXException`

### getError

public String getError()
Retrieve the error message set by the `org.xml.sax.ErrorHandler` methods. If no error has been found, `null` is returned.

Returns:
  A string describing the error encountered

### warning

public void warning(SAXParseException ex) throws SAXException
A method required by the `org.xml.sax.ErrorHandler` interface

Specified by:
  `warning` in interface `ErrorHandler`
Overrides:
  `warning` in class `DefaultHandler`
Parameters:
  `ex` - A parsing exception
Throws:
  `SAXException`

### error

public void error(SAXParseException ex) throws SAXException
A method required by the `org.xml.sax.ErrorHandler` interface

Specified by:
  `error` in interface `ErrorHandler`
Overrides:
  `error` in class `DefaultHandler`
Parameters:
  `ex` - A parsing exception
Throws:
  `SAXException`

### fatalError

public void fatalError(SAXParseException ex) throws SAXException
A method required by the `org.xml.sax.ErrorHandler` interface

Specified by:
  `fatalError` in interface `ErrorHandler`
Overrides:
  `fatalError` in class `DefaultHandler`
Parameters:
  `ex` - A parsing exception
Throws:
  `SAXException`