PsiElement (final String name, final @NotNull PsiElement element) { final XmlFile containingXmlFile = XmlUtil.getContainingFile(element); final XmlTag nearestTag = PsiTreeUtil.getParentOfType(element, XmlTag.class, false); final XmlFile xmlFile = nearestTag != null && containingXmlFile != null ? XmlUtil.findDescriptorFile(nearestTag, containingXmlFile) : containingXmlFile; if (xmlFile != null) { final PsiElement[] result = new PsiElement[1]; XmlUtil.processXmlElements( xmlFile, new PsiElementProcessor() { @Override public boolean execute(final @NotNull PsiElement element) { if (element instanceof XmlEntityDecl) { final XmlEntityDecl entityDecl = (XmlEntityDecl)element; if (entityDecl.isInternalReference() && name.equals(entityDecl.getName())) { result[0] = entityDecl; return false; } } else if (element instanceof XmlElementDecl) { final XmlElementDecl entityDecl = (XmlElementDecl)element; if (name.equals(entityDecl.getName())) { result[0] = entityDecl; return false; } } return true; } }, true ); return result[0]; } return null; }