XML validation with schema or DTD

E

e1-1z7k-2x9v-nh13

I am parsing an XML document and want to enable validation. The
document is a JCA resource adapter deployment descriptor. In JCA 1.0
the deployment descriptor is specified via a DTD. In JCA 1.5 it is
specified by an XML schema. I have the following code:

public Document getXMLDocument(String fileName, boolean validation) {

Document result = null;
try {
DocumentBuilderFactory parserFactory =
DocumentBuilderFactory.newInstance();
parserFactory.setValidating(true);

//parserFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage",,
// "http://www.w3.org/2001/XMLSchema");
}
DocumentBuilder parser = parserFactory.newDocumentBuilder();
result = parser.parse(new File(fileName));
} catch (SAXException se) {
System.err.println(se.getMessage());
}
return result;
}

The DTD-specified document parses successfully but the schema-specified
document throws a SAXParseException with the message "Document is
invalid: no grammar found".

If I remove the commented out code, the schema-specified document
parses successfully but the DTD-specified document throws a
SAXParseException with the message "cvc-elt.1: Cannot find the
declaration of element 'connector'."

Other than scanning the file for <!DOCTYPE and conditionally setting
the schema language, is there any way to parse an XML document with
validation regardless of whether it is schema- or DTD-specified?

Kevin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top