code: private int getDocumentType() {
          NodeList children = getChildNodes();
          int elemCount = 0;
          for (int i = 0; i < children.getLength(); i++) {
              Node n = children.item(i);
              switch (n.getNodeType()) {
              case Node.ELEMENT_NODE:
                  elemCount++;
                  break;
              case Node.PROCESSING_INSTRUCTION_NODE:
              case Node.COMMENT_NODE:
                  continue;
              default:
                  return NON_XML;
              }
          }
          return elemCount <= 1 ? VALID_XML : NON_XML;
      }
docs: Check root node of a document to see if it conform to DOM Structure
  Model. The root node can only be ELEMENT_NODE,
  PROCESSING_INSTRUCTION_NODE or COMMENT_NODE.
  
  @return 1(NON_XML) if root node violates DOM Structure Model; otherwise
  0(VALID_XML).