xml - 如何验证 xml 文件在 sh 或 bash 中是否有效?

标签 xml bash sh xmllint

如何验证 XML 文件在 sh(最好)或 bash 中是否有效?

我有一个文件经常损坏,需要在我花时间调查根本问题时更换。

有没有使用 sh 或 bash 执行此任务的简单方法?

最佳答案

不直接与 bash 一起使用,但是 xmllint 相当广泛可用。

xmllint --format "${xmlfile}"

如果 XML 文件无效,这将以非零状态退出(提示:bash 中的 $? 为您提供最后一个命令的退出代码)。

关于xml - 如何验证 xml 文件在 sh 或 bash 中是否有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22099708/

相关文章:

xml - 使用 XSLT 检查节点是否存在

java - 如何绕过 "This expression is not supported in the current option setting"错误

regex - 如何仅在一行中查找第二个数字?

linux - 使用 `sh -cx` 导出脚本变量

html - 选择文本而不使用同级标记

linux - 从第一列中提取子字符串

Linux RADIUS 日志

linux - 我可以从 ssh 调用本地函数吗?

bash - 修复小型 Bash 程序中的 POSIX sh 警告

python - 告诉基于 contains() 的 XPath 查询在到达字母时停止?