views:

33

answers:

1

I perform XSD XML validation using the following classes:

import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;

The problem is that XSD error messages returned by validator are always in English language. Is it possible to call locale-aware validation with JAXP API?

A: 

JAXP is an API; it is up to the actual implementation (for example, Apache Xerces) to provide localization-aware messages.

Normally, though, system-level libraries and implementations (such as JAXP & Xerces) will provide messages localized based on the system's default locale (whatever is returned from the expression java.util.Locale.getDefault()); this is, again, OS-specific.

On Microsoft Windows, for example, you can change your system's default locale using the Regional Settings window.

If you want, you can override the "default locale" used by the JVM by specifying the user.language and user.region system properties (for example, -Duser.language=fr and -Duser.region=CA would make the JVM yield "Canadian French" as a default locale. Eventually, this setting will get to JAXP's code. If Xerces provides Canadian French resource bundles, then Canadian French messages will be emitted.

Isaac
The problem is that I want to pass the locale at the runtime.
Henryk Konsek
The JAXP standard doesn't provide means for specifying locale at runtime. I believe that the reason behind it is that it's highly unusual to really _need_ those messages being available in multiple locales at runtime. It's not the type of messages that typically appear to end-users, but to administrators; that's why, I believe, it was enough for the JAXP spec to suffice with one locale - the system's locale. Of course, it is possible that certain JAXP implementations provide a way to specify locales at runtime... but then you'll be binding yourself to a particular JAXP implementation.
Isaac