解释对多个 XML 文档应用多个 xpath 查询的规则
我需要构建一个组件,该组件将在输入中获取一些 XML 文档并检查以下类型的规则:
XML1:/bookstore/book[price>35.00] != null
and (XML2:/city/name = 'Montreal'
or XML3://customer[@language] contains 'en')
基本上我的组件应该能够:
- 用相应的 XML 文档替换 XML 标记(在冒号之前)
- 对此 XML 应用 xpath 查询文档
- 根据预期结果检查 xpath 输出(“=”、“!=”、“包含”)
- 遵循基本语法(“和”、“或”和括号)
- 判断规则是对还是错
您知道任何库吗哪个可以帮助我?也许JavaCC?
谢谢
I need to build a component which would take a few XML documents in input and check the following kind of rules:
XML1:/bookstore/book[price>35.00] != null
and (XML2:/city/name = 'Montreal'
or XML3://customer[@language] contains 'en')
Basically my component should be able to:
- substitute the XML tokens with the corresponding XML document(before colon)
- apply xpath query on this XML document
- check the xpath output against expected result ("=", "!=", "contains")
- follow the basic syntax ("and", "or" and parentheses)
- tell if the rule is true or false
Do you know any library which could help me? maybe JavaCC?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了评估 XPATH,我推荐 JAXEN。
Java XPath API (Java 5 / javax.xml .xpath)也是一个选项,但我还没有尝试过。
For evaluating XPATHs I recommend JAXEN.
The Java XPath API (Java 5 / javax.xml.xpath) is also an option, but I haven't tried it yet.
JavaCC 邮件列表上的有人给我指出了正确的方向,提到了 Schematron。它引导我到 Probatron 它似乎是可用的最好的 java 实现。
Schematron 网站声称该语言支持“跨链接和 XML 文档之间跳转以检查约束”,但 Probatron 似乎不允许这样做。我可能不会调整它或找到一个技巧(比如构建一个包含所有源文档的临时 XML 文档)。除此之外,看起来 Probatron 是适合我的库。
Somebody on the JavaCC mailing list pointed me to the right direction, mentioning Schematron. It led me to Probatron which seems to be the best java implementation available.
Schematron web site claims that the language supports "jump across links and between XML documents to check constraints" but it seems Probatron doesn't allow that. I may not to tweak it or find a trick for that (like building a temporary XML document containing all my source documents). Apart from that, it looks Probatron is the right library for me.