我正在寻找一个命令行工具来用XSD-1.1文件验证XML文件。
我已经下载并安装了libxerces2-java,然后尝试应用免费的开源XSD1.1验证工具?和命令行中的Xerces验证器,但它们都无法工作。
So,我的简单问题是:我可以在哪里获得/如何创建一个XSD-1.1验证工具,该工具可以从命令行运行以验证一个XML文件?请提供一个完整的解决方案,因为Java类路径等是它们自己的一个主题.
发布于 2019-06-12 18:58:17
最后,我找到了我自己问题的答案:我找到了博客帖子“免费开放源码XSD1.1验证工具?”,其中包含到文件xsd11-validator.jar (镜像1,镜像2)的链接。
你可以这样称呼它:
usage: java hu.unideb.inf.validator.SchemaValidator -if | -iu
[-sf | -su ]
-if,--instanceFile read instance from the file specified
-iu,--instanceUrl read instance from the URL specified
-sf,--schemaFile read schema from the file specified
-su,--schemaUrl read schema from the URL specified要运行它,可以使用以下命令行:
java -jar xsd11-validator.jar -sf schema.xsd -if instance.xml为了简化它的使用,我编写了以下bash脚本xsd.sh:
#!/bin/bash
if [ $# -eq 0 ]
then
echo "======== XSD 1.1 Validator (for local files) ========";
echo "=====================================================";
echo "Usage: xsd.sh XSDschemaFile.xsd XMLFileToValidate.xml";
echo "=====================================================";
echo "(To validate remote files you have to call xsd11-validator.jar directly)";
else
output=$( java -jar xsd11-validator.jar -sf $1 -if $2 2>&1 )
if [ -z "$output" ]
then
echo "=== Validation succeeded! ===";
exit 0
else
echo "=== Validation FAILED! ===";
echo "$output";
exit 1
fi
fi它可以使用以下命令轻松地验证XSD-1.1文件:
./xsd.sh schema.xsd input.xmlhttps://askubuntu.com/questions/1120727
复制相似问题