[jdom-interest] Feature request setSchemaLocation()

Laurent Bihanic laurent.bihanic at atosorigin.com
Mon Apr 28 06:13:53 PDT 2003


Paul H. Roubekas wrote:
> I have a project where there are several instances of xml files that
> validate against the same XSD (schema).  But since the schemaLocation=
> of an .xml file does not have the idea of searching a list of paths I
> must put a copy of the schema in each directory with an xml file.  This
> allows me to just list the schema file name in the schemaLocation=
> attribute.  The only other way is to use a relative path in the
> schemaLocation=, but even that does work because each xml file is at a
> different level in the directory structure of the application.  This is
> becoming a problem because I need to validate each xml file upon loading
> with the SAXParser.   I would love to have a method off the Document
> object called setSchemaLocation(URI).  Or am I missing something?
> XML:SPY puts out some Java code that suggest such a method exists in
> some parsers is that true?

All parsers support setting the schema location(s) through the SAX API using 
properties. Such settings override those present in the document.

Using JAXP 1.2 properties for schema validation (supported by Xerces 2.2+) and 
JDOM Beta 9 RC x:

    SAXBuilder builder = new SAXBuilder(true);

    builder.setProperty(
       "http://java.sun.com/xml/jaxp/properties/schemaLanguage",
       "http://www.w3.org/2001/XMLSchema");
    builder.setProperty(
       "http://java.sun.com/xml/jaxp/properties/schemaSource",
       new String[] { "soap-envelope.xsd", "weblog.xsd" });

    builder.build(...);

Hope this helps,

Laurent




More information about the jdom-interest mailing list