如何通过 xmllint 使用 XSD 验证 XML 文件 [英] how to Validate a XML file with XSD through xmllint

查看:24
本文介绍了如何通过 xmllint 使用 XSD 验证 XML 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用给定的 XSD 文件验证我的 xml 文件.认为最简单的方法是 xmllint,但我无法让它工作.谁能告诉我确切的命令?

i have to validate my xml file with a given XSD file. Figured the easiest way to do so would be xmllint, but i can't get it to work. Can anyone tell me the exact command?

我试过了:

     xmllint --valid myxsd.xsd myxml.xml

我做错了什么?这仅输出命令行中的 2 个文件

What am i doing wrong? This only outputs the 2 files in the command line

必须在控制台中进行,因为在构建过程中需要它

edit: have to do it in console, because it will be needed in a build process

推荐答案

想通了,不得不使用 --schema 而不是 --validate.

Figured it out, had to use --schema instead of --validate.

xmllint --schema yourxsd.xsd yourxml.xml --noout

--noout 确保您的 XSD 和 XML 代码不会显示.使用此选项,您将只会看到验证错误.

The --noout makes sure your code in XSD and XML doesn't show. With this option you will only see the Validation Errors.

这篇关于如何通过 xmllint 使用 XSD 验证 XML 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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