使用RelaxNG进行XML模式验证 [英] XML Schema Validation with RelaxNG

查看:323
本文介绍了使用RelaxNG进行XML模式验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以推荐哪种XML验证工具来提高性能和准确性,而每一个都是我们系统上的关键问题?我们有以下要求:

Which XML validation tools can you recommend for both performance and accuracy, each of which is a critical issue on our system? We have the following requirements:

  • 不是 xmllint(请参见下文)
  • 支持RelaxNG
  • 可以轻松地与Perl集成(这是可选的,但是会很好)
  • It is not xmllint (see below)
  • Supports RelaxNG
  • Can easily integrate with Perl (this is optional, but it would be nice)

为什么不使用xmllint? (这是背景,您可以根据需要跳过它)

Why not xmllint? (This is background and you can skip it if you like)

我们有一个大型的Perl系统,该系统使用RelaxNG来验证我们的XML.我们使用紧凑的RelaxNG格式 xmllint 进行实际验证.

We have a large Perl system which uses RelaxNG to validate our XML. We use the compact RelaxNG format and trang to convert it to the standard RelaxNG format. Then we do the actual validation via xmllint.

那是问题开始出现的时候.xmllint通常会出现错误地报告验证错误的问题.它不会给出错误的肯定或否定,但是如果文档未能通过验证,则xmllint经常会针对给定的错误报告错误的元素或属性.有时错误是正确的(不希望看到元素'bar'),但这仅仅是因为未报告先前的错误(因为'bar'应该在必需但缺少的元素'foo'之后,但是xmllint却没有"告诉我们).请注意,这是xmllint的长期存在的问题,即使最新版本也存在相同的问题.我们经常有大量的XML文档,错误报告错误会给客户和开发人员带来很多麻烦.

That's when the problems kick in. xmllint routinely has issues in reporting validation errors incorrectly. It doesn't give false positives or negatives, but if the document fails to validate, xmllint will often report the wrong element or attribute for a given error. Sometimes the error is correct ("did not expect to see element 'bar'), but only because a previous error was not reported (because 'bar' was supposed to be following the required but missing element 'foo', but xmllint doesn't tell us that bit). Note that this is a long-standing problem with xmllint and even the latest version has the same problems. We often have huge XML documents and misreporting the errors causes much grief for both clients and developers.

推荐答案

我认为JDrago有一个正确的想法,至少在目前,您需要避免使用基于libxml2的工具进行RNG验证.我在项目中也发现了这一点.我最近针对libxml2记录了两个有关RNG验证的错误.

I think that JDrago has the right idea, that you need to avoid libxml2-based tools for RNG validation, at least for now. I'm discovering this as well in my project. I recently logged two bugs against libxml2 concerning RNG validation.

我建议 jing .它是由Relax NG的创建者,XML世界中的佼佼者之一James Clark编写的.他还是您已经在使用的trang的作者.我最近在上面链接到的Google Code网站上恢复了该代码(和trang)的开发.

I recommend jing. It was written by James Clark, the creator of Relax NG and one of the leading lights in the XML world. He is also the author of trang, which you are already using. Development of this code (and of trang) recently resumed at the Google Code site I link to above.

事实证明,Jing始终符合我们的内容和架构,并提供了比libxml2更好的错误消息,尽管在这方面仍有很大的改进空间.

Jing has proved consistently correct with our content and schema, and to give much better error messages than libxml2, though there is still a lot of room for improvement in that regard.

jing相对于libxml2/xmllint的一个缺点是它目前不使用OASIS XML目录来解析指向模式的公共标识符和系统标识符以及URI.如果您包含了由"http" URI引用的架构,那么这将是一个问题-那些架构始终会通过网络获取.

The one shortcoming of jing vis a vis libxml2/xmllint is that it doesn't at present use OASIS XML catalogs to resolve public and system identifiers and URIs pointing to schemas. This would be an issue in case you have included schemas that are referred to by 'http' URI--those would always be fetched over the network.

这篇关于使用RelaxNG进行XML模式验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆