解释对多个 XML 文档应用多个 xpath 查询的规则

发布于 2024-08-25 18:06:45 字数 436 浏览 7 评论 0原文

我需要构建一个组件,该组件将在输入中获取一些 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

§普罗旺斯的薰衣草 2024-09-01 18:06:45

为了评估 XPATH,我推荐 JAXEN

Jaxen 是一个开源 XPath 库
用Java编写的。它适应于
许多不同的对象模型,
包括 DOM、XOM、dom4j 和 JDOM。
是否也可以写适配器
处理非 XML 树,例如
已编译的 Java 字节代码或 Java bean
作为 XML,从而使您能够查询
这些树也带有 XPath。

Java XPath API (Java 5 / javax.xml .xpath)也是一个选项,但我还没有尝试过。

For evaluating XPATHs I recommend JAXEN.

Jaxen is an open source XPath library
written in Java. It is adaptable to
many different object models,
including DOM, XOM, dom4j, and JDOM.
Is it also possible to write adapters
that treat non-XML trees such as
compiled Java byte code or Java beans
as XML, thus enabling you to query
these trees with XPath too.

The Java XPath API (Java 5 / javax.xml.xpath) is also an option, but I haven't tried it yet.

酒绊 2024-09-01 18:06:45

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文