private static @Nullable XSModel getXSModel(XmlFile file) {

    ValidateXmlActionHandler handler = new ValidateXmlActionHandler(false) {
      @Override
      protected SAXParser createParser() throws SAXException, ParserConfigurationException {
        SAXParser parser = super.createParser();
        if (parser != null) {
          parser.getXMLReader().setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE, true);
        }
        return parser;
      }
    };
    handler.setErrorReporter(new ErrorReporter(handler) {

      int count;
      @Override
      public void processError(SAXParseException ex, ValidateXmlActionHandler.ProblemType warning) throws SAXException {
        if (warning != ValidateXmlActionHandler.ProblemType.WARNING && count++ > 100) {
          throw new SAXException(ex);
        }
      }

      @Override
      public boolean isUniqueProblem(SAXParseException e) {
        return true;
      }
    });

    handler.doValidate(file);
    XMLGrammarPool grammarPool = ValidateXmlActionHandler.getGrammarPool(file);
    if (grammarPool == null) {
      return null;
    }
    Grammar[] grammars = grammarPool.retrieveInitialGrammarSet(XMLGrammarDescription.XML_SCHEMA);

    return grammars.length == 0 ? null : ((XSGrammar)grammars[0]).toXSModel(ContainerUtil.map(grammars, grammar -> (XSGrammar)grammar, new XSGrammar[0]));
  }
private static @Nullable XSModel getXSModel(XmlFile file)