DocType docType = document.getDocType();
if (docType != null) {
Element element = document.getRootElement();
String rootElement = element.getName();
MarkupFamily family = docType.getMarkupFamily();
String expectedRoot = docType.getRoot();
if (!family
.compareRootElementNames(rootElement, expectedRoot)) {
throw new IllegalStateException(
"Expected root element name" + expectedRoot +
" does not match actual root element name " +
rootElement);