[jdom-interest] Schema Validation
Kevin L. Cobb
kevin.cobb at emergint.com
Thu Aug 11 07:26:52 PDT 2005
This may be slightly off topic for JDOM but I'm hoping its close enough.
I've done the appropriate GOOGLEing for the answer but just can't seem
to figure it out.
I am trying to implement schema validation BUT my schema is on the file
system, not on a web server. I keep getting an error in the SAX parser,
"no protocol" which I assume means it can't find the schema (this could
be an incorrect assumption but I don't know at this point). Here is my
code. I'm setting the variable, schemaURI, to a URI like
file://c:/mySchema.xsd
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~
SAXBuilder builder = new
SAXBuilder("org.apache.xerces.parsers.SAXParser");
builder.setValidation(true);
builder.setErrorHandler(new MySAXChecker());
// turn on schema support
builder.setFeature("http://apache.org/xml/features/validation/schema",
true);
builder.setProperty("http://apache.org/xml/properties/schema/external-no
NamespaceSchemaLocation", schemaURI);
try {
builder.build(xmlToValidate);
}
catch (JDOMException e) {
System.out.println("Source xml is not well-formed.");
System.out.println(e.getMessage());
}
catch (IOException e) {
System.out.println("Could not get source XML: " + e.getMessage());
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Kevin L Cobb, MT(ASCP), SCJP2
Senior Software Engineer
Emergint, Inc.
2724 River Green Circle
Louisville, KY 40206
Kevin.Cobb at emergint.com <mailto:Kevin.Cobb at emergint.com>
502.896.6210 ext 255
502.896.6170 fax
The preceding e-mail message and attachments, if any, contains
information that is confidential and qualifies as such under the
Definition of Confidential Information in the Non-Disclosure Agreement,
and may constitute non-public information and trade secrets. It is
intended to be conveyed only to the designated recipient(s). If you are
not an intended recipient of this message, please notify the sender at
502.896.6210.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20050811/b54237fa/attachment.htm
More information about the jdom-interest
mailing list