我目前正在开发的 Web 应用程序针对存储在服务器上的 xsd 验证用户提供的 xml 文件。问题是如果 xml 验证失败,错误消息应该是俄语的。我的解析器正在工作 - 它提供错误消息,但只有英文
String parserClass = "org.apache.xerces.parsers.SAXParser";
String validationFeature = "http://xml.org/sax/features/validation";
String schemaFeature = "http://apache.org/xml/features/validation/schema";
XMLReader reader = null;
reader = XMLReaderFactory.createXMLReader(parserClass);
reader.setFeature(validationFeature,true);
reader.setFeature(schemaFeature,true);
BatchContentHandler contentHandler = new BatchContentHandler(reader);
reader.setContentHandler(contentHandler);
BatchErrorHandler errorHandler = new BatchErrorHandler(reader);
reader.setErrorHandler(errorHandler);
reader.setFeature("http://apache.org/xml/features/continue-after-fatal-error", true);
reader.parse(new InputSource(new ByteArrayInputStream(streamedXML)));
它工作正常 - 错误消息是英文的。在 Xerces 2.11.0 (Java) 中阅读这篇文章Locale specific messages以及这篇文章https://www.java.net//node/699069我添加了这些行
Locale l = new Locale("ru", "RU");
reader.setProperty("http://apache.org/xml/properties/locale", l);
我还将 XMLSchemaMessages_RU.properties 文件添加到 jar 中。现在我得到 NULL 指针异常。有什么想法或提示吗?提前致谢!