Set<String> (final @NotNull PsiElement element, @NotNull XmlFile file) { if (!(element instanceof XmlTag tag)) { return Collections.emptySet(); } final String name = tag.getLocalName(); final Set<String> byTagName = getNamespacesByTagName(name, file); if (!byTagName.isEmpty()) { Set<String> filtered = new HashSet<>(byTagName); filtered.removeAll(Arrays.asList(tag.knownNamespaces())); return filtered; } final Set<String> set = guessNamespace(file.getProject(), name); set.removeAll(Arrays.asList(tag.knownNamespaces())); final XmlTag parentTag = tag.getParentTag(); ns: for (Iterator<String> i = set.iterator(); i.hasNext();) { final String s = i.next(); final Collection<XmlFile> namespaces = XmlUtil.findNSFilesByURI(s, element.getProject(), ModuleUtilCore.findModuleForPsiElement(file)); for (XmlFile namespace : namespaces) { final XmlDocument document = namespace.getDocument(); assert document != null; final XmlNSDescriptor nsDescriptor = (XmlNSDescriptor)document.getMetaData(); assert nsDescriptor != null; if (parentTag != null) { continue ns; } for (XmlElementDescriptor descriptor : nsDescriptor.getRootElementsDescriptors(document)) { if (descriptor == null) { LOG.error(nsDescriptor + " returned null element for getRootElementsDescriptors() array"); continue; } if (descriptor.getName().equals(name)) { continue ns; } } } i.remove(); } return set; }