1
我目前正在使用的Web應用程序驗證用戶提供的xml文件是否存儲在服務器上的xsd。問題是如果xml驗證失敗,錯誤信息應該是俄文。我有我的語法分析器 - 它提供了錯誤信息,但只有英文SAX 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)));
它工作正常 - 錯誤信息是英文的。 閱讀這篇文章Locale specific messages in Xerces 2.11.0 (Java),也這篇文章https://www.java.net//node/699069我添加了這些行
Locale l = new Locale("ru", "RU");
reader.setProperty("http://apache.org/xml/properties/locale", l);
我還添加了XMLSchemaMessages_RU.properties文件到瓶子裏。現在我得到NULL指針異常。任何想法或提示?提前致謝!
仍然得到java.lang.NullPointerException :( –
你可以編輯你的文章添加錯誤的整個堆棧跟蹤嗎?也許這將是有用的 – Paolo
看看這個[stackoverflow post](http://stackoverflow.com/questions/6848106/java -jre-how-to-add-localized-resources-to-stantard-jre-resources)。 – Paolo