Проверка схемы, как отобразить удобные для пользователя сообщения проверки?

Предположение:

На скомпилированном языке, одна система (компилятор) добирается для наблюдения всего кода, требуемого сделать строгий контроль типов. Интерпретаторы обычно только видят крошечный бит программы за один раз и так не могут сделать такой перекрестной проверки.

, Но это не жесткое правило - было бы довольно возможно сделать интерпретируемый язык со строгим контролем типов, но это будет идти вразрез с видом "свободного" общего чувства интерпретируемых языков.

5
задан pribeiro 28 September 2009 в 19:37
поделиться

2 ответа

Некоторое время назад я задал аналогичный вопрос .

Я пришел к выводу, что не существует способа сопоставления ошибок, и это то, что вам нужно сделать самостоятельно .

Надеюсь, что кто-то сможет добиться большего!

0
ответ дан 15 December 2019 в 01:06
поделиться

Not that I know of. You will probably have to create some custom code to adapt your error messages. One way might be to define a set of regular expressions that can pull out the relevant pieces of the validator's error messages and then plug them back into your own error messages. Something like this comes to mind (not optimized, doesn't handle general case, etc. but I think you'll get the idea):

String uglyMessage = "cvc-complex-type.2.4.b: The content of element 'node' is not complete. One of '{\"\":offer,\"\":links}' is expected.";

String findRegex = "cvc-complex-type\\.2\\.4\\.b: The content of element '(\\w+)' is not complete\\. One of '\\{\"\":(\\w+),\"\":(\\w+)}' is expected\\.";

String replaceRegex = "The element '$1' is not complete. The child elements '$2' and '$3' are expected.";

String userFriendlyMessage = Pattern.compile(findRegex).matcher(uglyMessage).replaceAll(replaceRegex);

System.out.println(userFriendlyMessage);
// OUTPUT:
//   The element 'node' is not complete. The child elements 'offer' and 'links' are expected.

I suspect those validator error messages are vendor-specific so if you don't have control over the XML validator in your deployed app, this may not work for you.

3
ответ дан 15 December 2019 в 01:06
поделиться
Другие вопросы по тегам:

Похожие вопросы: