Saxparserfactory setvalidating true
Another way of achieving this effect -- but only in the case of schema validation -- is by explicitly instructing the parser to validate against a given schema; effectively overriding the schema location hint.Just set the property to a value specifying the schema to use.
For a JAXP application, the key class is SAXParser Factory factory = SAXParser Instance(); Namespace Aware(true); Validating(true); SAXParser parser = SAXParser(); XMLReader reader = XMLReader(); Entity Resolver(new Catalog Resolver()); Error Handler(new Default Error Handler()); reader.parse(input Source); .
Your application then installs a resolver, whose job it is to consult the catalog whenever an external resource is needed.
The Apache xml-commons project's Resolver package, from Norman Walsh, is a collection of Java classes for working with XML Catalogs.
For the first example, let's look at a common situation where XML Catalogs are useful: in providing a local copy of a DTD.
Suppose you want to check that a page is valid XHTML -- before you put it on your website, for example.