我正在使用xmllint Linux命令(xmllint description),我想捕获错误代码以便在脚本中使用它。我该怎么做呢?
谢谢
发布于 2012-10-18 22:06:27
您可以这样做:
if xmllint --xpath '/my/path' file.xml; then
echo "success"
else
echo >&2 "error"
exit 1
fi如果您没有安装 --xpath ,请执行以下操作:
file=/path/to/file
xpath='/foo/bar'
result="$(echo "cat $xpath" | xmllint --shell "$file")"
if [ $(echo "$result" | wc -l) -gt 2 ]; then
echo "success"
else
echo >&2 "error"
exit 1
fi发布于 2015-11-09 17:59:22
或者,如果您有要用来验证xml文件的模式,可以这样做: your_xml_file 2>myxmlval.out --noout --schema your_xsd_file
myxmlval.out将是一个捕获由xmllint模式验证产生错误的文件
https://stackoverflow.com/questions/12956534
复制相似问题