schemaType = decl.getType();
instr.setSchemaType(schemaType);
// TODO: this causes validation against the type, rather than the declaration:
// are identity constraints being tested on the top-level element?
itemType = new CombinedNodeTest(
new NameTest(Type.ELEMENT, nameCode, env.getNamePool()),
Token.INTERSECT,
new ContentTypeTest(Type.ELEMENT, schemaType, config));
try {
schemaType.analyzeContentExpression(content, Type.ELEMENT, env);
} catch (XPathException e) {
e.setErrorCode(instr.isXSLT() ? "XTTE1510" : "XQDY0027");
e.setLocator(instr);
throw e;
}
SchemaType xsiType = instr.getXSIType(env);
if (xsiType != null) {
xsiType.analyzeContentExpression(content, Type.ELEMENT, env);
try {
config.checkTypeDerivationIsOK(xsiType, schemaType, 0);
} catch (SchemaException e) {
ValidationException ve = new ValidationException("The specified xsi:type " + xsiType.getDescription() +
" is not validly derived from the required type " + schemaType.getDescription());
ve.setConstraintReference(1, "cvc-elt", "4.3");
ve.setErrorCode(instr.isXSLT() ? "XTTE1515" : "XQDY0027");
ve.setLocator((Locator)instr);
throw ve;
}
}
} else if (validation == Validation.LAX) {
SchemaDeclaration decl = config.getElementDeclaration(nameCode & 0xfffff);
if (decl == null) {
env.issueWarning("There is no global element declaration for " +
env.getNamePool().getDisplayName(nameCode), instr);
itemType = new NameTest(Type.ELEMENT, nameCode, env.getNamePool());
} else {
schemaType = decl.getType();
instr.setSchemaType(schemaType);
itemType = new CombinedNodeTest(
new NameTest(Type.ELEMENT, nameCode, env.getNamePool()),
Token.INTERSECT,
new ContentTypeTest(Type.ELEMENT, instr.getSchemaType(), config));
try {
schemaType.analyzeContentExpression(content, Type.ELEMENT, env);
} catch (XPathException e) {
e.setErrorCode(instr.isXSLT() ? "XTTE1515" : "XQDY0027");
e.setLocator(instr);
throw e;
}
}
} else if (validation == Validation.PRESERVE) {
// we know the result will be an element of type xs:anyType
itemType = new CombinedNodeTest(
new NameTest(Type.ELEMENT, nameCode, env.getNamePool()),
Token.INTERSECT,
new ContentTypeTest(Type.ELEMENT, AnyType.getInstance(), config));
} else {
// we know the result will be an untyped element
itemType = new CombinedNodeTest(
new NameTest(Type.ELEMENT, nameCode, env.getNamePool()),
Token.INTERSECT,
new ContentTypeTest(Type.ELEMENT, Untyped.getInstance(), config));
}
} else {
itemType = new CombinedNodeTest(
new NameTest(Type.ELEMENT, nameCode, env.getNamePool()),
Token.INTERSECT,
new ContentTypeTest(Type.ELEMENT, schemaType, config)
);
try {
schemaType.analyzeContentExpression(content, Type.ELEMENT, env);