@Override
  public @Nls String generateDoc(PsiElement element, final PsiElement originalElement) {
    if (element instanceof XmlElementDecl) {
      PsiElement curElement = XmlUtil.findPreviousComment(element);

      if (curElement!=null) {
        return formatDocFromComment(curElement, ((XmlElementDecl)element).getNameElement().getText());
      }
    }
    else if (element instanceof XmlTag tag) {
      MyPsiElementProcessor processor = new MyPsiElementProcessor();
      String name = tag.getAttributeValue(NAME_ATTR_NAME);
      String typeName = null;

      if (originalElement != null && originalElement.getParent() instanceof XmlAttributeValue value) {
        String toSearch = value.getValue();
        XmlTag enumerationTag;

        if (XmlUtil.ENUMERATION_TAG_NAME.equals(tag.getLocalName())) {
          enumerationTag = tag;
          name = enumerationTag.getAttributeValue(XmlUtil.VALUE_ATTR_NAME);
        } else {
          enumerationTag = findEnumerationValue(toSearch, tag);
          name = toSearch;
        }

        if (enumerationTag != null) {
          XmlUtil.processXmlElements(enumerationTag,processor, true);

          if (processor.result != null) {
            typeName = XmlBundle.message("xml.javadoc.enumeration.value.message");
          }
        }
      }

      if (processor.result == null) XmlUtil.processXmlElements(tag,processor, true);

      if (processor.result == null) {
        XmlTag declaration = getComplexOrSimpleTypeDefinition(element, originalElement);

        if (declaration != null) {
          XmlUtil.processXmlElements(declaration,processor, true);
          name = declaration.getAttributeValue(NAME_ATTR_NAME);
          typeName = XmlBundle.message("xml.javadoc.complex.type.message");
        }
      }
      if (processor.result == null) {
        final PsiElement comment = XmlUtil.findPreviousComment(element);
        if (comment != null) {
          return formatDocFromComment(comment, ((XmlTag)element).getName());
        }
      }

      String doc = generateDoc(processor.result, name, typeName, processor.version);
      if (doc != null && originalElement != null) {
        doc += generateHtmlAdditionalDocTemplate(originalElement);
      }
      return doc;

    } else if (element instanceof XmlAttributeDecl) {
      // Check for comment before attlist, it should not be right after previous declaration
      final PsiElement parent = element.getParent();
      final PsiElement previousComment = XmlUtil.findPreviousComment(parent);
      final String referenceName = ((XmlAttributeDecl)element).getNameElement().getText();

      if (previousComment != null) {
        final PsiElement prevSibling = previousComment.getPrevSibling();

        if (prevSibling == null ||
            ( prevSibling instanceof PsiWhiteSpace &&
              prevSibling.getText().indexOf('\n') >= 0
            )
           ) {
          return formatDocFromComment(previousComment, referenceName);
        }
      }

      return findDocRightAfterElement(parent, referenceName);
    } else if (element instanceof XmlEntityDecl entityDecl) {

      return findDocRightAfterElement(element, entityDecl.getName());
    }

    return null;
  }
@Override
  public @Nls String generateDoc(PsiElement element, final PsiElement originalElement)