SchemaPrefix (final XmlTag context, String namespacePrefix) { @NonNls String nsDeclarationAttrName = null; for(XmlTag t = context; t != null; t = t.getParentTag()) { if (t.hasNamespaceDeclarations()) { if (nsDeclarationAttrName == null) nsDeclarationAttrName = namespacePrefix.length() > 0 ? "xmlns:"+namespacePrefix:"xmlns"; XmlAttribute attribute = t.getAttribute(nsDeclarationAttrName); if (attribute != null) { final String attrPrefix = attribute.getNamespacePrefix(); final TextRange textRange = TextRange.from(attrPrefix.length() + 1, namespacePrefix.length()); return new SchemaPrefix(attribute, textRange, namespacePrefix); } } } return null; }