private static @Nullable XmlNSDescriptor getNsDescriptorFormDocType(
    @NotNull XmlDocument document, final XmlDoctype doctype, final XmlFile containingFile, final boolean forHtml
  ) {
    XmlNSDescriptor descriptor = getNSDescriptorFromMetaData(document, doctype.getMarkupDecl(), true);

    final String filePath = getFilePathForLogging(containingFile);

    final String dtdUri = XmlUtil.getDtdUri(doctype);
    LOG.debug("DTD url for doctype " + doctype.getText() + " in file " + filePath + " is " + dtdUri);

    if (dtdUri != null && !dtdUri.isEmpty()) {
      XmlFile xmlFile = XmlUtil.findNamespace(containingFile, dtdUri);
      if (xmlFile == null) {
        // try to auto-detect it
        xmlFile = XmlNamespaceIndex.guessDtd(dtdUri, containingFile);
      }
      final String schemaFilePath = getFilePathForLogging(xmlFile);

      LOG.debug("Schema file for " + filePath + " is " + schemaFilePath);

      XmlNSDescriptor descriptorFromDtd = getNSDescriptorFromMetaData(document,
                                                                      xmlFile == null
                                                                      ? null
                                                                      : AstLoadingFilter.forceAllowTreeLoading(xmlFile,
                                                                                                               xmlFile::getDocument),
                                                                      forHtml);

      LOG.debug("Descriptor from meta data for schema file " +
                schemaFilePath +
                " is " +
                (descriptorFromDtd != null ? descriptorFromDtd.getClass().getCanonicalName() : "NULL"));

      if (descriptor != null && descriptorFromDtd != null) {
        descriptor = new XmlNSDescriptorSequence(new XmlNSDescriptor[]{descriptor, descriptorFromDtd});
      }
      else if (descriptorFromDtd != null) {
        descriptor = descriptorFromDtd;
      }
    }
    return descriptor;
  }
private static @Nullable XmlNSDescriptor getNsDescriptorFormDocType(
    @NotNull XmlDocument document, final XmlDoctype doctype, final XmlFile containingFile, final boolean forHtml
  )