* @param schemaReference - the path to the complex type or element to be validated against in the schema
* @param handler - the error handler
* @return true if the document fragment is valid, false otherwise
*/
public boolean validate(Element elem, XMLDescriptor xmlDescriptor, ErrorHandler errorHandler) throws XMLPlatformException {
XMLSchemaReference schemaReference = xmlDescriptor.getSchemaReference();
NamespaceResolver nsResolver = xmlDescriptor.getNamespaceResolver();
// build a schema using the URL in the schema reference, and setup a validator
XMLSchema xmlSchema;
XSDValidator validator = null;
try {
Object[] args = { schemaReference.getURL() };
xmlSchema = (XMLSchema)buildSchemaMethod.invoke(new XSDBuilder(), args);
validator = new XSDValidator();
} catch (Exception ex) {
throw XMLPlatformException.xmlPlatformValidationException(ex);
}
// set the schema to be validated against
validator.setXMLProperty(XSDValidator.FIXED_SCHEMA, xmlSchema);
// set the node to be validated against
XSDNode xsdNode = getNodeFromSchemaReference(xmlSchema, schemaReference, nsResolver);
// if xsdNode is null, the schema context string is empty or the target could not be found
if (xsdNode == null) {
validator.setXMLProperty(XSDNode.ROOT_NODE, null);
}
if (schemaReference.getType() == XMLSchemaReference.ELEMENT) {
if (xmlDescriptor.getDefaultRootElement() != null) {
validator.setXMLProperty(XSDNode.ROOT_NODE, xsdNode);
} else {
validator.setXMLProperty(XSDNode.ROOT_NODE, ((XSDElement)xsdNode).getType());
}