XML Schema (XSD) 验证工具? [英] XML Schema (XSD) validation tool?

查看:75
本文介绍了XML Schema (XSD) 验证工具?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在办公室,我们目前正在编写一个应用程序,该应用程序将根据给定的模式生成 XML 文件.我们在 .XSD 文件中有架构.

At the office we are currently writing an application that will generate XML files against a schema that we were given. We have the schema in an .XSD file.

是否有工具或库可用于自动化测试以检查生成的 XML 是否与架构匹配?

Are there tool or libraries that we can use for automated testing to check that the generated XML matches the schema?

我们更喜欢适合商业用途的免费工具,尽管我们不会捆绑架构检查器,因此它只需要在开发过程中可供开发人员使用.

We would prefer free tools that are appropriate for commercial use although we won't be bundling the schema checker so it only needs to be usable by devs during development.

如果这有什么不同,我们的开发语言是 C++,尽管我认为不应该,因为我们可以生成 xml 文件,然后通过在测试中调用单独的程序来进行验证.

Our development language is C++ if that makes any difference, although I don't think it should as we could generate the xml file and then do validation by calling a separate program in the test.

推荐答案

经过一番研究,我认为最好的答案是 Xerces 因为它实现了所有的 XSD,所以是跨平台的并且被广泛使用.我创建了一个 github 上的小型 Java 项目 以使用默认的 JRE 解析器从命令行进行验证,通常是 Xerces.这可以在 Windows/Mac/Linux 上使用.

After some research, I think the best answer is Xerces, as it implements all of XSD, is cross-platform and widely used. I've created a small Java project on github to validate from the command line using the default JRE parser, which is normally Xerces. This can be used on Windows/Mac/Linux.

如果您愿意,也可以使用 C++ 版本的 Xerces.StdInParse 实用程序 可用于从命令行调用它.此外,下面的评论者指出了这个更完整的包装器实用程序.

There is also a C++ version of Xerces available if you'd rather use that. The StdInParse utility can be used to call it from the command line. Also, a commenter below points to this more complete wrapper utility.

您也可以使用 xmllint,它是 libxml 的一部分.您可能已经安装了它.示例用法:

You could also use xmllint, which is part of libxml. You may well already have it installed. Example usage:

xmllint --noout --schema XSD_FILE XML_FILE

一个问题是 libxml 没有实现所有规范,所以你可能会遇到问题:(

One problem is that libxml doesn't implement all of the specification, so you may run into issues :(

或者,如果您使用的是 Windows,则可以使用 msxml,但您将需要某种包装器来调用它,例如这篇 DDJ 文章.但是,似乎大多数 Windows 用户都使用 XML 编辑器,例如 Notepad++(如 Nate 的答案 中所述)或 XML Notepad 2007 为 SteveC 建议(还有几个商业编辑器,我不会在这里提及).

Alternatively, if you are on Windows, you can use msxml, but you will need some sort of wrapper to call it, such as the GUI one described in this DDJ article. However, it seems most people on Windows use an XML Editor, such as Notepad++ (as described in Nate's answer) or XML Notepad 2007 as suggested by SteveC (there are also several commercial editors which I won't mention here).

最后,不幸的是,您会发现不同的程序会给出不同的结果.这主要是由于 XSD 规范的复杂性.您可能想使用多种工具测试您的架构.

Finally, you'll find different programs will, unfortunately, give different results. This is largely due to the complexity of the XSD spec. You may want to test your schema with several tools.

更新:我在 博文.

这篇关于XML Schema (XSD) 验证工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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