@NotNull
  @Override
  public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
    return new XmlElementVisitor() {
      @Override
      public void visitXmlAttribute(@NotNull XmlAttribute attribute) {
        PsiFile file = holder.getFile();
        if (!(file instanceof XmlFile)) return;

        XmlRefCountHolder refCountHolder = XmlRefCountHolder.getRefCountHolder((XmlFile)file);
        if (refCountHolder == null) return;
        @Nullable XmlTag parent = attribute.getParent();
        if (parent == null) return;
        if (!attribute.isNamespaceDeclaration()) {
          if (getDefaultLocation(parent) == attribute) {
             // check the parent has attribute with namespace decl
            for (XmlAttribute other : parent.getAttributes()) {
              if (!other.isNamespaceDeclaration()) continue;
              String namespace = other.getValue();
              String declaredPrefix = getDeclaredPrefix(other);
              if (namespace != null && !refCountHolder.isInUse(declaredPrefix) && declaredPrefix.isEmpty() && !isUsedImplicitly(other)) {
                holder.registerProblem(attribute, XmlAnalysisBundle.message("xml.inspections.unused.schema.location"), ProblemHighlightType.LIKE_UNUSED_SYMBOL,
                                       new RemoveNamespaceDeclarationFix(declaredPrefix, true, true));
                return;
              }
            }
          }
          checkUnusedLocations(attribute, holder, refCountHolder);
          return;
        }

        String namespace = attribute.getValue();
        String declaredPrefix = getDeclaredPrefix(attribute);
        if (namespace != null && !refCountHolder.isInUse(declaredPrefix)) {

          if (isUsedImplicitly(attribute)) return;

          XmlAttributeValue value = attribute.getValueElement();
          assert value != null;
          holder.registerProblem(attribute, XmlAnalysisBundle.message("xml.inspections.unused.schema.declaration"), ProblemHighlightType.LIKE_UNUSED_SYMBOL,
                                 new RemoveNamespaceDeclarationFix(declaredPrefix, false, !refCountHolder.isUsedNamespace(namespace)));

          if (!declaredPrefix.isEmpty()) {
            if (!refCountHolder.isUsedNamespace(namespace)) {
              for (PsiReference reference : getLocationReferences(namespace, parent)) {
                if (!XmlHighlightVisitor.hasBadResolve(reference, false))
                  holder.registerProblemForReference(reference, ProblemHighlightType.LIKE_UNUSED_SYMBOL, XmlAnalysisBundle.message("xml.inspections.unused.schema.location"),
                                                     new RemoveNamespaceDeclarationFix(declaredPrefix, true, true));
              }
            }
          }
        }
      }
    };
  }
@NotNull
  @Override
  public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly)