private static Set<String> extractEmbeddedFileReferences(XmlFile file, XmlFile context, final String url) {
    if (context != null) {
      XmlEntityCache.copyEntityCaches(file, context);
    }

    Set<String> result = new LinkedHashSet<>();
    XmlUtil.processXmlElements(
      file,
      element -> {
        if (element instanceof XmlEntityDecl) {
          String candidateName = null;

          for (PsiElement e = element.getLastChild(); e != null; e = e.getPrevSibling()) {
            if (e instanceof XmlAttributeValue && candidateName == null) {
              candidateName = e.getText().substring(1, e.getTextLength() - 1);
            }
            else if (e instanceof XmlToken &&
                     candidateName != null &&
                     (((XmlToken)e).getTokenType() == XmlTokenType.XML_DOCTYPE_PUBLIC ||
                      ((XmlToken)e).getTokenType() == XmlTokenType.XML_DOCTYPE_SYSTEM
                     )
              ) {
              result.add(candidateName);
              break;
            }
          }
        }
        else if (element instanceof XmlTag tag) {
          String schemaLocation = tag.getAttributeValue(XmlUtil.SCHEMA_LOCATION_ATT);

          if (schemaLocation != null) {
            // processing xsd:import && xsd:include
            final PsiReference[] references = tag.getAttribute(XmlUtil.SCHEMA_LOCATION_ATT).getValueElement().getReferences();
            if (references.length > 0) {
              String extension = FileUtilRt.getExtension(new File(url).getName());
              final String namespace = tag.getAttributeValue("namespace");
              if (namespace != null &&
                  schemaLocation.indexOf('/') == -1 &&
                  !extension.equals(FileUtilRt.getExtension(schemaLocation))) {
                result.add(namespace.substring(0, namespace.lastIndexOf('/') + 1) + schemaLocation);
              }
              else {
                result.add(schemaLocation);
              }
            }
          }
          else {
            schemaLocation = tag.getAttributeValue(XmlUtil.SCHEMA_LOCATION_ATT, XmlUtil.XML_SCHEMA_INSTANCE_URI);
            if (schemaLocation != null) {
              final StringTokenizer tokenizer = new StringTokenizer(schemaLocation);

              while (tokenizer.hasMoreTokens()) {
                tokenizer.nextToken();
                if (!tokenizer.hasMoreTokens()) break;
                String location = tokenizer.nextToken();
                result.add(location);
              }
            }
          }
        }

        return true;
      },
      true,
      true
    );
    return result;
  }
private static Set<String> extractEmbeddedFileReferences(XmlFile file, XmlFile context, final String url)