case ElementItem:
level++;
break;
case ElementEndItem:
level--;
ElementEnd end = (ElementEnd)item;
if (level<0) {
if (end.getValidity()!=Validity.VALID) {
StringBuilder builder = new StringBuilder();
Iterator errors = validate.getErrors();
while (errors.hasNext()) {
builder.append("\n");
builder.append(errors.next().toString());
}
throw new XMLException("Element "+end.getName()+" is not valid:"+builder.toString());
}
if (topLevelElements!=null) {
Name name = end.getName();
if (!topLevelElements.contains(name)) {
throw new XMLException("Unexpected document element "+name);
}
}
}