xml - 使用 Schematron 检查是否在目标 XML 文档中定义了参考 XML 的每个元素
问题描述
我想使用 Schematron 来验证 XML 文档,方法是检查它是否包含来自单独的参考 XML 源的所有必需元素。例如,我有一个 XML 文件requiredIngredients.xml
,它定义:
<requiredIngredients>
<ingredient>Water</ingredient>
<ingredient>Flour</ingredient>
<ingredient>Salt</ingredient>
</requiredIngredients>
使用它,我想验证另一个包含以下内容的 XML 文件:
<myRecipe>
<ingredient>Sugar</ingredient>
<ingredient>Water</ingredient>
</myRecipe>
在这种情况下,我需要两个单独的错误,一个是缺少“Flour”,另一个是缺少“Salt”。如果我想使用类似...的东西,请使用 Schematron
<rule context="/myRecipe">...</rule>
...我可以使用函数(例如检查)对requiredIngredients.xml
文件进行测试,但这只会产生一个错误。我可以通过将自己转换为一组 Schematron 断言来实现这一点,但我真的希望将其分开,因为可能存在大量此类文件(将其视为我的验证规则的输入以及要验证的实际 XML)。document
every .. in .. satisfies
requiredIngredients.xml
任何想法都会非常受欢迎!
解决方案
推荐阅读
- python - create_engine() 缺少 1 个必需的位置参数:'engine_opts
- aspnetboilerplate - Automapper 配置文件的 UserFriendlyException
- android - 将 Android 计费库更新到最新 2.0 后,应用无法正确连接到许可服务
- c# - 如何从 blob 类型的 MySql 数据库中获取图像?
- python - Kivy App 每次启动时都会加载其他颜色而不是默认颜色(错误)
- xml - 在 XSLT 1.0 中使用计时逻辑的 JSON 输出
- python - 如何使用 keras 顺序模型使用 gridsearchCV 调整 l2 正则化器
- excel - 优化VBA数组而不是范围?
- mysql - 从时间戳列中选择特定的月份和年份记录mysql
- android - 我想要一个通过 TextView 中的值可见的制作按钮