@Override
  public void visitXmlProcessingInstruction(XmlProcessingInstruction processingInstruction) {
    super.visitXmlProcessingInstruction(processingInstruction);
    PsiElement parent = processingInstruction.getParent();

    if (parent instanceof XmlProlog && processingInstruction.getText().startsWith("<?xml")) {
      for (PsiElement e = PsiTreeUtil.prevLeaf(processingInstruction);
          e != null;
          e = PsiTreeUtil.prevLeaf(e)) {
        if (e instanceof PsiWhiteSpace && PsiTreeUtil.prevLeaf(e) != null
            || e instanceof OuterLanguageElement) {
          continue;
        }
        PsiElement eParent = e.getParent();
        if (eParent instanceof PsiComment) e = eParent;
        if (eParent instanceof XmlProcessingInstruction) break;

        addToResults(
            HighlightInfo.createHighlightInfo(
                HighlightInfoType.ERROR,
                e,
                XmlErrorMessages.message("xml.declaration.should.precede.all.document.content")));
      }
    }
  }
 public void accept(@NotNull PsiElementVisitor visitor) {
   if (visitor instanceof XmlElementVisitor) {
     ((XmlElementVisitor) visitor).visitXmlDocument(this);
   } else {
     visitor.visitElement(this);
   }
 }