PsiElement (PsiElement contextNode) { PsiElement element = contextNode; while (element != null) { if (MyPsiUtil.isNameElement(element)) { return element.getParent(); } else if (MyPsiUtil.isStartTag(contextNode) || MyPsiUtil.isEndTag(contextNode)) { return element.getParent(); } else if (element instanceof XmlAttribute) { return element; } else if (element instanceof XmlComment) { return element; } else if (element instanceof XmlProcessingInstruction) { return element; } else if (element instanceof XmlText) { return element; } element = element.getParent(); } return null; }