找到你要的答案

Q:Can XSD assertion violations be warnings rather than errors?

Q:可以断言的是XSD违规警告而不是错误?

I've been using XML Schema 1.1 because I want to define some assertions in the schema. The thing is whether I can handle any assertion errors as simple warnings.

The reason is that any inconsistencies are automatically handled in my web site, so I would like to notify the user what changes have been made.

Maybe there is a suitable alternative to "assert" that I'm not aware of.

我一直在使用xml架构1.1,因为我想在架构中定义一些断言。问题是我是否可以处理任何断言错误作为简单警告。

原因是,在我的网站中会自动处理任何不一致之处,所以我想通知用户发生了什么变化。

也许有一个合适的选择“断言”,我不知道。

answer1: 回答1:

No, XSD has no such notion of warning, and does not directly support user-controlled messaging regarding constraint violations.

You might look into Schematron where assertion messages and @role and @flag attributes can be specified.


Update per OP comment:

Yes, you could write a custom SAX Error Handler to intercept and change a validating parser's default error messages. (See Tip: Validation and the SAX ErrorHandler interface) This wouldn't have natural representation declaratively in the XSD itself, however, unless you also leveraged xsd:appinfo in some creative manner.

不,没有这样的概念的XSD的警告,并没有直接支持用户控制的消息对于违反约束。

你可以看看那里的消息和@作用Schematron断言和@标志属性可以指定。


每次更新评论:

是的,你可以写一个自定义错误处理程序拦截并改变SAX验证解析器的默认错误消息。(见提示:验证和萨克斯ErrorHandler接口)这不会自然表示声明在XSD本身,但是,除非你也利用XSD appInfo在一些有创意的方式。

answer2: 回答2:

Whether an invalid document is the cause of an error or a warning is not a function of the schema; it is determined by the validator and the invoker of the validator.

Most validators by default assume that they should raise an error on invalid input, but there is nothing that requires that behavior. The validator you are using may have an invocation-time option that allows you to request a warning, instead -- or if you are invoking a parser from a language like Java, you can of course catch the exception yourself. You can almost certainly identify whether the cause of invalidity was a false assertion by examining the error code supplied by the validator.

And if you are a user of any validator (especially if you are a paying customer), you might consider letting the developers know that you would like an interface to the validator that behaves differently; it's obvious that they will never know if you don't tell them.

一个无效的文件是否是一个错误或警告的原因不是一个模式的功能;它是由验证器和验证程序的调用程序确定。

默认情况下,大多数验证器认为他们应该对无效输入产生一个错误,但没有要求的行为。你使用验证器可以调用时间选项,允许你请求一个警告,相反,如果你调用一个程序语言如java,当然你可以捕捉异常的自己。你几乎可以肯定确认无效的原因是由检查由验证器提供错误代码错误的断言。

如果你是任何验证器用户(特别是如果你是一个付费客户),你可能会考虑让开发商知道你喜欢一个接口,表现出不同的验证;很明显,他们将永远不会知道,如果你不告诉他们。

xml  xsd  xml-validation  xsd-1.1