Set<String> () { final Set<String> prefixes = new HashSet<>(); myXPathFile.accept(new PsiRecursiveElementVisitor(){ @Override public void visitElement(@NotNull PsiElement element) { if (element instanceof QNameElement) { final PsiReference[] references = element.getReferences(); for (PsiReference reference : references) { if (reference instanceof PrefixReference prefixReference) { if (prefixReference.isUnresolved()) { prefixes.add(prefixReference.getPrefix()); } } } } super.visitElement(element); } }); return prefixes; }