如何通过xmllint [duplicate]使用XSD验证XML文件

时间:2021-10-03 14:11:00

This question already has an answer here:

这个问题已经有了答案:

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?

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

I tried:

我试着:

     xmllint --valid myxsd.xsd myxml.xml

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

编辑:必须在控制台执行,因为在构建过程中需要它

1 个解决方案

#1


30  

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

找到了,必须使用模式而不是验证。

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

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

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

#1


30  

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

找到了,必须使用模式而不是验证。

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

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

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