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
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