StringWriter strw = new StringWriter();
// No content whatsoever is allowed with EMPTY.
// Let's first test with a regualr child element:
XMLStreamWriter2 sw = getDTDValidatingWriter(strw, dtdStr, nsAware, repairing);
sw.writeStartElement("root");
try {
sw.writeStartElement("leaf");
fail(modeDesc+" Expected a validation exception when trying to add an element into EMPTY content model");
} catch (XMLValidationException vex) {
// expected...
}
sw.close();
// Then with an empty child
sw = getDTDValidatingWriter(strw, dtdStr, nsAware, repairing);
sw.writeStartElement("root");
try {
sw.writeEmptyElement("leaf");
fail(modeDesc+" Expected a validation exception when trying to add an element into EMPTY content model");
} catch (XMLValidationException vex) {
// expected...
}
sw.close();
// Then with any text (even just white space):
sw = getDTDValidatingWriter(strw, dtdStr, nsAware, repairing);
sw.writeStartElement("root");
try {
sw.writeCharacters(" ");
fail(modeDesc+" Expected a validation exception when trying to any text into EMPTY content model");
} catch (XMLValidationException vex) { }
sw.close();
// Then CDATA
sw = getDTDValidatingWriter(strw, dtdStr, nsAware, repairing);
sw.writeStartElement("root");
try {
sw.writeCData("foo");
fail(modeDesc+" Expected a validation exception when trying to add CDATA into EMPTY content model");
} catch (XMLValidationException vex) { }
sw.close();
// Then ENTITY
sw = getDTDValidatingWriter(strw, dtdStr, nsAware, repairing);
sw.writeStartElement("root");
try {
sw.writeEntityRef("amp");
fail(modeDesc+" Expected a validation exception when trying to add CDATA into EMPTY content model");
} catch (XMLValidationException vex) { }
sw.close();
// Then comment
sw = getDTDValidatingWriter(strw, dtdStr, nsAware, repairing);
sw.writeStartElement("root");
try {
sw.writeComment("comment");
fail(modeDesc+" Expected a validation exception when trying to add comment into EMPTY content model");
} catch (XMLValidationException vex) { }
sw.close();
// Then proc. instr.
sw = getDTDValidatingWriter(strw, dtdStr, nsAware, repairing);
sw.writeStartElement("root");
try {
sw.writeProcessingInstruction("target", "data");
fail(modeDesc+" Expected a validation exception when trying to add processing instruction into EMPTY content model");
} catch (XMLValidationException vex) { }
sw.close();
}
}