Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Protected Ctors](https://developer.android.com/reference/javax/xml/validation/Validator#proctors) \| [Methods](https://developer.android.com/reference/javax/xml/validation/Validator#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/javax/xml/validation/Validator#inhmethods)

# Validator


`
public


abstract
class
Validator
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | javax.xml.validation.Validator |

<br />

*** ** * ** ***

<br />

A processor that checks an XML document against `https://developer.android.com/reference/javax/xml/validation/Schema`.


A validator is a thread-unsafe and non-reentrant object.
In other words, it is the application's responsibility to make
sure that one `https://developer.android.com/reference/javax/xml/validation/Validator` object is not used from
more than one thread at any given time, and while the validate
method is invoked, applications may not recursively call
the validate method.


Note that while the `https://developer.android.com/reference/javax/xml/validation/Validator#validate(javax.xml.transform.Source)` and `https://developer.android.com/reference/javax/xml/validation/Validator#validate(javax.xml.transform.Source,%20javax.xml.transform.Result)`
methods take a `https://developer.android.com/reference/javax/xml/transform/Source` instance, the `Source`
instance must be a `SAXSource`, `DOMSource`, `StAXSource` or `StreamSource`.

## Summary

| ### Protected constructors ||
|---|---|
| ` https://developer.android.com/reference/javax/xml/validation/Validator#Validator()() ` Constructor for derived classes. |

| ### Public methods ||
|---|---|
| ` abstract https://developer.android.com/reference/org/xml/sax/ErrorHandler` | ` https://developer.android.com/reference/javax/xml/validation/Validator#getErrorHandler()() ` Gets the current `https://developer.android.com/reference/org/xml/sax/ErrorHandler` set to this `https://developer.android.com/reference/javax/xml/validation/Validator`. |
| ` boolean` | ` https://developer.android.com/reference/javax/xml/validation/Validator#getFeature(java.lang.String)(https://developer.android.com/reference/java/lang/String name) ` Look up the value of a feature flag. |
| ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/javax/xml/validation/Validator#getProperty(java.lang.String)(https://developer.android.com/reference/java/lang/String name) ` Look up the value of a property. |
| ` abstract https://developer.android.com/reference/org/w3c/dom/ls/LSResourceResolver` | ` https://developer.android.com/reference/javax/xml/validation/Validator#getResourceResolver()() ` Gets the current `https://developer.android.com/reference/org/w3c/dom/ls/LSResourceResolver` set to this `https://developer.android.com/reference/javax/xml/validation/Validator`. |
| ` abstract void` | ` https://developer.android.com/reference/javax/xml/validation/Validator#reset()() ` <br /> Reset this `Validator` to its original configuration. |
| ` abstract void` | ` https://developer.android.com/reference/javax/xml/validation/Validator#setErrorHandler(org.xml.sax.ErrorHandler)(https://developer.android.com/reference/org/xml/sax/ErrorHandler errorHandler) ` Sets the `https://developer.android.com/reference/org/xml/sax/ErrorHandler` to receive errors encountered during the `validate` method invocation. |
| ` void` | ` https://developer.android.com/reference/javax/xml/validation/Validator#setFeature(java.lang.String,%20boolean)(https://developer.android.com/reference/java/lang/String name, boolean value) ` Set the value of a feature flag. |
| ` void` | ` https://developer.android.com/reference/javax/xml/validation/Validator#setProperty(java.lang.String,%20java.lang.Object)(https://developer.android.com/reference/java/lang/String name, https://developer.android.com/reference/java/lang/Object object) ` Set the value of a property. |
| ` abstract void` | ` https://developer.android.com/reference/javax/xml/validation/Validator#setResourceResolver(org.w3c.dom.ls.LSResourceResolver)(https://developer.android.com/reference/org/w3c/dom/ls/LSResourceResolver resourceResolver) ` Sets the `https://developer.android.com/reference/org/w3c/dom/ls/LSResourceResolver` to customize resource resolution while in a validation episode. |
| ` void` | ` https://developer.android.com/reference/javax/xml/validation/Validator#validate(javax.xml.transform.Source)(https://developer.android.com/reference/javax/xml/transform/Source source) ` Validates the specified input. |
| ` abstract void` | ` https://developer.android.com/reference/javax/xml/validation/Validator#validate(javax.xml.transform.Source,%20javax.xml.transform.Result)(https://developer.android.com/reference/javax/xml/transform/Source source, https://developer.android.com/reference/javax/xml/transform/Result result) ` Validates the specified input and send the augmented validation result to the specified output. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Protected constructors

### Validator

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected Validator ()
```

Constructor for derived classes.


The constructor does nothing.


Derived classes must create `https://developer.android.com/reference/javax/xml/validation/Validator` objects that have
null `https://developer.android.com/reference/org/xml/sax/ErrorHandler` and
null `https://developer.android.com/reference/org/w3c/dom/ls/LSResourceResolver`.

<br />

## Public methods

### getErrorHandler

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract ErrorHandler getErrorHandler ()
```

Gets the current `https://developer.android.com/reference/org/xml/sax/ErrorHandler` set to this `https://developer.android.com/reference/javax/xml/validation/Validator`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/org/xml/sax/ErrorHandler` | This method returns the object that was last set through the `https://developer.android.com/reference/javax/xml/validation/Validator#setErrorHandler(org.xml.sax.ErrorHandler)` method, or null if that method has never been called since this `https://developer.android.com/reference/javax/xml/validation/Validator` has created. <br /> |

**See also:**

- `https://developer.android.com/reference/javax/xml/validation/Validator#setErrorHandler(org.xml.sax.ErrorHandler)`

### getFeature

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean getFeature (String name)
```

Look up the value of a feature flag.

The feature name is any fully-qualified URI. It is
possible for a `https://developer.android.com/reference/javax/xml/validation/Validator` to recognize a feature name but
temporarily be unable to return its value.
Some feature values may be available only in specific
contexts, such as before, during, or after a validation.

Implementors are free (and encouraged) to invent their own features,
using names built on their own URIs.

<br />

<br />

| Parameters ||
|---|---|
| `name` | `String`: The feature name, which is a non-null fully-qualified URI. <br /> |

| Returns ||
|---|---|
| `boolean` | The current value of the feature (true or false). <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException` | When the name parameter is null. |
| `https://developer.android.com/reference/org/xml/sax/SAXNotRecognizedException` | If the feature value can't be assigned or retrieved. |
| `https://developer.android.com/reference/org/xml/sax/SAXNotSupportedException` | When the `https://developer.android.com/reference/javax/xml/validation/Validator` recognizes the feature name but cannot determine its value at this time. |

**See also:**

- `https://developer.android.com/reference/javax/xml/validation/Validator#setFeature(java.lang.String,%20boolean)`

### getProperty

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Object getProperty (String name)
```

Look up the value of a property.

The property name is any fully-qualified URI. It is
possible for a `https://developer.android.com/reference/javax/xml/validation/Validator` to recognize a property name but
temporarily be unable to return its value.
Some property values may be available only in specific
contexts, such as before, during, or after a validation.

`https://developer.android.com/reference/javax/xml/validation/Validator`s are not required to recognize any specific
property names.

Implementors are free (and encouraged) to invent their own properties,
using names built on their own URIs.

<br />

<br />

| Parameters ||
|---|---|
| `name` | `String`: The property name, which is a non-null fully-qualified URI. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/Object` | The current value of the property. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException` | When the name parameter is null. |
| `https://developer.android.com/reference/org/xml/sax/SAXNotRecognizedException` | If the property value can't be assigned or retrieved. |
| `https://developer.android.com/reference/org/xml/sax/SAXNotSupportedException` | When the XMLReader recognizes the property name but cannot determine its value at this time. |

**See also:**

- `https://developer.android.com/reference/javax/xml/validation/Validator#setProperty(java.lang.String,%20java.lang.Object)`

### getResourceResolver

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract LSResourceResolver getResourceResolver ()
```

Gets the current `https://developer.android.com/reference/org/w3c/dom/ls/LSResourceResolver` set to this `https://developer.android.com/reference/javax/xml/validation/Validator`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/org/w3c/dom/ls/LSResourceResolver` | This method returns the object that was last set through the `https://developer.android.com/reference/javax/xml/validation/Validator#setResourceResolver(org.w3c.dom.ls.LSResourceResolver)` method, or null if that method has never been called since this `https://developer.android.com/reference/javax/xml/validation/Validator` has created. <br /> |

**See also:**

- `https://developer.android.com/reference/javax/xml/validation/Validator#setErrorHandler(org.xml.sax.ErrorHandler)`

### reset

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void reset ()
```

<br />

Reset this `Validator` to its original configuration.

`Validator` is reset to the same state as when it was created with
`https://developer.android.com/reference/javax/xml/validation/Schema#newValidator()`.
`reset()` is designed to allow the reuse of existing `Validator`s
thus saving resources associated with the creation of new `Validator`s.

The reset `Validator` is not guaranteed to have the same `https://developer.android.com/reference/org/w3c/dom/ls/LSResourceResolver` or `https://developer.android.com/reference/org/xml/sax/ErrorHandler`
`Object`s, e.g. `https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)`. It is guaranteed to have a functionally equal
`LSResourceResolver` and `ErrorHandler`.

<br />

<br />

### setErrorHandler

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void setErrorHandler (ErrorHandler errorHandler)
```

Sets the `https://developer.android.com/reference/org/xml/sax/ErrorHandler` to receive errors encountered
during the `validate` method invocation.


Error handler can be used to customize the error handling process
during a validation. When an `https://developer.android.com/reference/org/xml/sax/ErrorHandler` is set,
errors found during the validation will be first sent
to the `https://developer.android.com/reference/org/xml/sax/ErrorHandler`.


The error handler can abort further validation immediately
by throwing `https://developer.android.com/reference/org/xml/sax/SAXException` from the handler. Or for example
it can print an error to the screen and try to continue the
validation by returning normally from the `https://developer.android.com/reference/org/xml/sax/ErrorHandler`


If any `https://developer.android.com/reference/java/lang/Throwable` is thrown from an `https://developer.android.com/reference/org/xml/sax/ErrorHandler`,
the caller of the `validate` method will be thrown
the same `https://developer.android.com/reference/java/lang/Throwable` object.


`https://developer.android.com/reference/javax/xml/validation/Validator` is not allowed to
throw `https://developer.android.com/reference/org/xml/sax/SAXException` without first reporting it to
`https://developer.android.com/reference/org/xml/sax/ErrorHandler`.


When the `https://developer.android.com/reference/org/xml/sax/ErrorHandler` is null, the implementation will
behave as if the following `https://developer.android.com/reference/org/xml/sax/ErrorHandler` is set:

    class DraconianErrorHandler implements https://developer.android.com/reference/org/xml/sax/ErrorHandler {
        public void fatalError( https://developer.android.com/reference/org/xml/sax/SAXParseException e ) throws https://developer.android.com/reference/org/xml/sax/SAXException {
            throw e;
        }
        public void error( https://developer.android.com/reference/org/xml/sax/SAXParseException e ) throws https://developer.android.com/reference/org/xml/sax/SAXException {
            throw e;
        }
        public void warning( https://developer.android.com/reference/org/xml/sax/SAXParseException e ) throws https://developer.android.com/reference/org/xml/sax/SAXException {
            // noop
        }
    }


When a new `https://developer.android.com/reference/javax/xml/validation/Validator` object is created, initially
this field is set to null.

<br />

| Parameters ||
|---|---|
| `errorHandler` | `ErrorHandler`: A new error handler to be set. This parameter can be null. <br /> |

### setFeature

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setFeature (String name, 
                boolean value)
```

Set the value of a feature flag.


Feature can be used to control the way a `https://developer.android.com/reference/javax/xml/validation/Validator`
parses schemas, although `https://developer.android.com/reference/javax/xml/validation/Validator`s are not required
to recognize any specific property names.

The feature name is any fully-qualified URI. It is
possible for a `https://developer.android.com/reference/javax/xml/validation/Validator` to expose a feature value but
to be unable to change the current value.
Some feature values may be immutable or mutable only
in specific contexts, such as before, during, or after
a validation.

<br />

<br />

| Parameters ||
|---|---|
| `name` | `String`: The feature name, which is a non-null fully-qualified URI. <br /> |
| `value` | `boolean`: The requested value of the feature (true or false). <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException` | When the name parameter is null. |
| `https://developer.android.com/reference/org/xml/sax/SAXNotRecognizedException` | If the feature value can't be assigned or retrieved. |
| `https://developer.android.com/reference/org/xml/sax/SAXNotSupportedException` | When the `https://developer.android.com/reference/javax/xml/validation/Validator` recognizes the feature name but cannot set the requested value. |

**See also:**

- `https://developer.android.com/reference/javax/xml/validation/Validator#getFeature(java.lang.String)`

### setProperty

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setProperty (String name, 
                Object object)
```

Set the value of a property.

The property name is any fully-qualified URI. It is
possible for a `https://developer.android.com/reference/javax/xml/validation/Validator` to recognize a property name but
to be unable to change the current value.
Some property values may be immutable or mutable only
in specific contexts, such as before, during, or after
a validation.

`https://developer.android.com/reference/javax/xml/validation/Validator`s are not required to recognize setting
any specific property names.

<br />

<br />

| Parameters ||
|---|---|
| `name` | `String`: The property name, which is a non-null fully-qualified URI. <br /> |
| `object` | `Object`: The requested value for the property. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException` | When the name parameter is null. |
| `https://developer.android.com/reference/org/xml/sax/SAXNotRecognizedException` | If the property value can't be assigned or retrieved. |
| `https://developer.android.com/reference/org/xml/sax/SAXNotSupportedException` | When the `https://developer.android.com/reference/javax/xml/validation/Validator` recognizes the property name but cannot set the requested value. |

### setResourceResolver

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void setResourceResolver (LSResourceResolver resourceResolver)
```

Sets the `https://developer.android.com/reference/org/w3c/dom/ls/LSResourceResolver` to customize
resource resolution while in a validation episode.


`https://developer.android.com/reference/javax/xml/validation/Validator` uses a `https://developer.android.com/reference/org/w3c/dom/ls/LSResourceResolver`
when it needs to locate external resources while a validation,
although exactly what constitutes "locating external resources" is
up to each schema language.


When the `https://developer.android.com/reference/org/w3c/dom/ls/LSResourceResolver` is null, the implementation will
behave as if the following `https://developer.android.com/reference/org/w3c/dom/ls/LSResourceResolver` is set:

    class DumbLSResourceResolver implements https://developer.android.com/reference/org/w3c/dom/ls/LSResourceResolver {
        public https://developer.android.com/reference/org/w3c/dom/ls/LSInput resolveResource(
            String publicId, String systemId, String baseURI) {

            return null; // always return null
        }
    }


If a `https://developer.android.com/reference/org/w3c/dom/ls/LSResourceResolver` throws a `https://developer.android.com/reference/java/lang/RuntimeException`
(or instances of its derived classes),
then the `https://developer.android.com/reference/javax/xml/validation/Validator` will abort the parsing and
the caller of the `validate` method will receive
the same `https://developer.android.com/reference/java/lang/RuntimeException`.


When a new `https://developer.android.com/reference/javax/xml/validation/Validator` object is created, initially
this field is set to null.

<br />

| Parameters ||
|---|---|
| `resourceResolver` | `LSResourceResolver`: A new resource resolver to be set. This parameter can be null. <br /> |

### validate

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void validate (Source source)
```

Validates the specified input.


This is just a convenience method of:

```
validate(source,null);
```

<br />

<br />

| Parameters ||
|---|---|
| `source` | `Source` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` |   |
| `https://developer.android.com/reference/org/xml/sax/SAXException` |   |

**See also:**

- `https://developer.android.com/reference/javax/xml/validation/Validator#setErrorHandler(org.xml.sax.ErrorHandler)`

### validate

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void validate (Source source, 
                Result result)
```

Validates the specified input and send the augmented validation
result to the specified output.


This method places the following restrictions on the types of
the `https://developer.android.com/reference/javax/xml/transform/Source`/`https://developer.android.com/reference/javax/xml/transform/Result` accepted.

#### `https://developer.android.com/reference/javax/xml/transform/Source`/`https://developer.android.com/reference/javax/xml/transform/Result` accepted:

|   | `https://developer.android.com/reference/javax/xml/transform/sax/SAXSource` | `https://developer.android.com/reference/javax/xml/transform/dom/DOMSource` | `https://developer.android.com/reference/javax/xml/transform/stream/StreamSource` |
|---|---|---|---|---|
| null | OK | OK | OK | OK |
| `https://developer.android.com/reference/javax/xml/transform/sax/SAXResult` | OK | Err | Err | Err |
| `https://developer.android.com/reference/javax/xml/transform/dom/DOMResult` | Err | OK | Err | Err |
| `https://developer.android.com/reference/javax/xml/transform/stream/StreamResult` | Err | Err | Err | OK |


To validate one `https://developer.android.com/reference/javax/xml/transform/Source` into another kind of `https://developer.android.com/reference/javax/xml/transform/Result`, use the identity transformer
(see `https://developer.android.com/reference/javax/xml/transform/TransformerFactory#newTransformer()`).


Errors found during the validation is sent to the specified
`https://developer.android.com/reference/org/xml/sax/ErrorHandler`.


If a document is valid, or if a document contains some errors
but none of them were fatal and the `https://developer.android.com/reference/org/xml/sax/ErrorHandler` didn't
throw any exception, then the method returns normally.

<br />

| Parameters ||
|---|---|
| `source` | `Source`: XML to be validated. Must not be null. <br /> |
| `result` | `Result`: The `https://developer.android.com/reference/javax/xml/transform/Result` object that receives (possibly augmented) XML. This parameter can be null if the caller is not interested in it. Note that when a `https://developer.android.com/reference/javax/xml/transform/dom/DOMResult` is used, a validator might just pass the same DOM node from `https://developer.android.com/reference/javax/xml/transform/dom/DOMSource` to `https://developer.android.com/reference/javax/xml/transform/dom/DOMResult` (in which case source.getNode()==result.getNode()), it might copy the entire DOM tree, or it might alter the node given by the source. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | If the validator is processing a `https://developer.android.com/reference/javax/xml/transform/sax/SAXSource` and the underlying `https://developer.android.com/reference/org/xml/sax/XMLReader` throws an `https://developer.android.com/reference/java/io/IOException`. |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | If the `https://developer.android.com/reference/javax/xml/transform/Result` type doesn't match the `https://developer.android.com/reference/javax/xml/transform/Source` type, or if the specified source is not a `https://developer.android.com/reference/javax/xml/transform/sax/SAXSource`, `https://developer.android.com/reference/javax/xml/transform/dom/DOMSource` or `https://developer.android.com/reference/javax/xml/transform/stream/StreamSource`. |
| `https://developer.android.com/reference/java/lang/NullPointerException` | If the source parameter is null. |
| `https://developer.android.com/reference/org/xml/sax/SAXException` | If the `https://developer.android.com/reference/org/xml/sax/ErrorHandler` throws a `https://developer.android.com/reference/org/xml/sax/SAXException` or if a fatal error is found and the `https://developer.android.com/reference/org/xml/sax/ErrorHandler` returns normally. |

**See also:**

- `https://developer.android.com/reference/javax/xml/validation/Validator#validate(javax.xml.transform.Source)`