public class SchemaUtil extends Object
javax.xml.validation.Schema
is an
opaque object, most of these actually work with DOM documents that
contain an XSD.Constructor and Description |
---|
SchemaUtil() |
Modifier and Type | Method and Description |
---|---|
static Document[] |
combineSchemas(InputSource... sources)
Parses and combines one or more input sources to produce an array
of DOM documents containing schema components.
|
static SchemaFactory |
newFactory(ErrorHandler errHandler)
Creates a new
javax.xml.validation.SchemaFactory instance
for validation with XML Schema, which reports errors via the specified
error handler. |
static Schema |
newSchema(InputSource... sources)
Parses one or more input sources to produce a
Schema
object. |
static Schema |
newSchema(SchemaFactory factory,
Document... sources)
Compiles one or more DOM documents to produce a
Schema
object from the passed factory. |
static Schema |
newSchema(SchemaFactory factory,
InputSource... sources)
Parses one or more input sources to produce a
Schema
object from the passed factory. |
static Document[] |
parseSources(InputSource[] sources)
Parses an array of
org.xml.sax.InputSource objects, and
performs some (minimal) level of validation on them. |
public static SchemaFactory newFactory(ErrorHandler errHandler)
javax.xml.validation.SchemaFactory
instance
for validation with XML Schema, which reports errors via the specified
error handler.public static Schema newSchema(InputSource... sources)
Schema
object. Validators produced from this schema will throw an
XmlException
on any error.
The caller is responsible for ordering the sources so that imported
schemas appear first. This method is unable to combine sources from
the same target namespace; see combineSchemas()
for explanation.
sources
- The source schema documents. Note that these are
org.xml.sax.InputSource
objects for
consistency with other classes in this library;
not the javax.xml.transform.Source
objects used by SchemaFactory
.IllegalArgumentException
- if invoked without any sources.XmlException
- if unable to create the schema object.public static Schema newSchema(SchemaFactory factory, InputSource... sources)
Schema
object from the passed factory. This call is synchronized on the
factory, which the JDK 1.5 docs describe as not threadsafe.
The caller is responsible for ordering the sources so that imported
schemas appear first. This method is unable to combine sources from
the same target namespace; see combineSchemas()
for explanation.
factory
- Used to create the schema object.sources
- The source schema documents. Note that these are
org.xml.sax.InputSource
objects for
consistency with other classes in this library;
not the javax.xml.transform.Source
objects used by SchemaFactory
.IllegalArgumentException
- if invoked without any sources.XmlException
- if unable to parse a source or compile the schema.public static Schema newSchema(SchemaFactory factory, Document... sources)
Schema
object from the passed factory. This call is synchronized on the
factory, which the JDK 1.5 docs describe as not threadsafe.
The caller is responsible for ordering the documents so that imported
schemas appear first. This method is unable to combine sources from
the same target namespace; see combineSchemas()
for explanation.
factory
- Used to create the schema object.sources
- The source schema documents.IllegalArgumentException
- if invoked without any sources.XmlException
- if unable to compile the schema.public static Document[] combineSchemas(InputSource... sources)
When combining schema documents with the same namespace, all top-level
attributes (eg, elementFormDefault
) come from the first
source specified for the namespace. The <xsd:schema>
element, and its attributes, are ignored for subsequent sources for
that namespace.
Sources must contain <xsd:import>
elements for any
referenced schemas. If the sources contain a schema for the specified
target namespace, any schemaLocation
specification will
be ignored.
sources
- The source schema documents. Note that these are
org.xml.sax.InputSource
objects for
consistency with other classes in this library;
not the javax.xml.transform.Source
objects used by SchemaFactory
.IllegalArgumentException
- if invoked without any sources, or if
a source does not appear to be an XML Schema document (current
checking is minimal, but that may change).XmlException
- on any parse error, or if the sources do not
appear to be valid XSD documents.public static Document[] parseSources(InputSource[] sources)
org.xml.sax.InputSource
objects, and
performs some (minimal) level of validation on them. This method is
called by newSchema()
and combineSchema()
,
and will identify the source that wasn't valid.IllegalArgumentException
- if no sources specified (this is
a common check for callers).