in Education by
I've got a problem similar to this question: SAXParseException localized I'm trying to parse a XML file and get a list of parser errors (SAXParseException) in a several languages for example: XmlImporter.importFile(params, "en") should return a list of errors in English, XmlImporter.importFile(params, "fr") should return a list of errors in French, XmlImporter.importFile(params, "pl") should return a list of errors in Polish language. Every call of XmlImporter.importFile(params, "...") may be with a different locale. This is my validation method: private void validate(String xmlFilePath, String schemaFilePath) throws Exception { SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = schemaFactory.newSchema(new File(schemaFilePath)); Validator validator = schema.newValidator(); XmlErrorHandler errorHandler = new XmlErrorHandler(); validator.setErrorHandler(errorHandler); try (InputStream stream = new FileInputStream(new File(xmlFilePath))) { validator.validate(new StreamSource(stream)); } XmlErrorHandler: public class XmlErrorHandler implements ErrorHandler { private List errorsList = new ArrayList<>(); public List getErrorsList() { return errorsList; } @Override public void warning(SAXParseException exception) throws SAXException { errorsList.add(prepareExceptionDescription(exception)); } @Override public void error(SAXParseException exception) throws SAXException { errorsList.add(prepareExceptionDescription(exception)); } @Override public void fatalError(SAXParseException exception) throws SAXException { errorsList.add(prepareExceptionDescription(exception)); } private String prepareExceptionDescription(SAXParseException exception) { return "Error: " + "colNumber: " + exception.getColumnNumber() + " line number: " + exception.getLineNumber() + " message: " + exception.getLocalizedMessage(); } } I assume, that I need to pass somehow/somewhere java.util.Locale/String to get in exception.getLocalizedMessage() custom message (in en, fr or pl)? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
By the default Xerces (Java Parser which is used to convert XML file to Java object) could provide internationalization for given languages: XMLSchemaMessages_de.properties XMLSchemaMessages_es.properties XMLSchemaMessages_fr.properties XMLSchemaMessages_it.properties XMLSchemaMessages_ja.properties XMLSchemaMessages_ko.properties XMLSchemaMessages_pt_BR.properties XMLSchemaMessages_sv.properties XMLSchemaMessages_zh_CN.properties XMLSchemaMessages_zh_TW.properties To provide internationalization in other language: Get XMLSchemaMessages.properties file from Apache Xerces and rename file to a new file XMLSchemaMessages_LANG.properties, where LANG needs to be changed to a new language. Update file's messages to a new language and place this file in a classpath (You can add this file to src\main\resources\com\sun\org\apache\xerces\internal\impl\msg) Exceptions will be visible in a new language (messages will be taken from XMLSchemaMessages_LANG.properties file)

Related questions

0 votes
    I'm getting below error while fetching a response from SOAP service from a java client: [javax.xml.bind ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 8, 2022 in Education by JackTerrance
0 votes
    I have googled a lot about pagination of importing XML data into InDesign CS5, but problems are still ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 9, 2022 in Education by JackTerrance
0 votes
    I have googled a lot about pagination of importing XML data into InDesign CS5, but problems are still ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    Which method to use while working with XML fragments, instead of XML()? (a) XMLInterface() (b) ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 23, 2021 in Education by JackTerrance
0 votes
    I am constructing a tuning fork app. The fork should allow up to 12 preset pitches. Moreover, I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 27, 2022 in Education by JackTerrance
0 votes
    Rather than rewriting the entire contents of an xml file when a single element is updated, is there a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 26, 2022 in Education by JackTerrance
0 votes
    This is a sample (edited slightly, but you get the idea) of my XML file: Test 192.168.1.1 Test ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I have an XML file which is structured as follows: place1 location1 place2 location2 place3 location3 These ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    Q: I allow my user to upload an xml file to insert its contents in my database. I ask if there' ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    Q: I allow my user to upload an xml file to insert its contents in my database. I ask if there' ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    Q: I allow my user to upload an xml file to insert its contents in my database. I ask if there' ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    Explain how XML file is called in d3.js?...
asked Nov 14, 2020 in Technology by JackTerrance
0 votes
    strong text [Plugin error at Note entity][1] [1]: Hi,Anyone ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 8, 2022 in Education by JackTerrance
0 votes
    I'm trying to import an XML file via a web page in a Ruby on Rails application, the code ruby ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    As stated in the title, i'm looking for an XML schema (XSD-file) for the Glade markup language? ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
...