boolean valid = true; DocType doctype = document.getDocType(); if (doctype == null) { valid = false; } else { // check doctype } Element root = document.getRootElement(); String uri = root.getNamespaceURI(); String prefix = root.getNamespacePrefix(); if (!uri.equals("http://www.w3.org/1999/xhtml")) { valid = false; } if (!prefix.equals("")) valid = false;